सक्रिय अधिगम (Active Learning)
Potato की annotation queue को model की अनिश्चितता के आधार पर पुनः क्रमबद्ध करें, पाँच query strategies, sklearn classifiers, cold-start प्रबंधन और restart के बाद भी बने रहने वाले models के साथ।
Active learning annotation queue को पुनः क्रमबद्ध करता है ताकि annotators को पहले वे instances दिखें जिन पर model सबसे कम निश्चित है, न कि corpus उसी क्रम में जिसमें वह आया था।
यह कैसे काम करता है
- संग्रह: annotations का एक प्रारंभिक सेट एकत्र करें
- प्रशिक्षण: अब तक label किए गए डेटा पर एक classifier प्रशिक्षित करें
- स्कोरिंग: बिना label वाले pool को अनिश्चितता के आधार पर स्कोर करें
- पुनः क्रमण: queue को ऐसे क्रमबद्ध करें कि सबसे अनिश्चित instances सबसे पहले आएँ
- Annotation: प्राथमिकता वाले instances को annotate करें
- पुनः प्रशिक्षण: annotations बढ़ने के साथ समय-समय पर model को फिर से प्रशिक्षित करें
एनोटेशन प्रयास वहाँ लगाएँ जहाँ मॉडल सबसे अधिक सीखता है
कॉन्फ़िगरेशन
बुनियादी सेटअप
active_learning:
enabled: true
schema_names:
- sentiment
min_annotations_per_instance: 1
min_instances_for_training: 20
update_frequency: 50
max_instances_to_reorder: 1000min_instances_for_training का default 10 है और update_frequency का 5। दोनों defaults इतने कम हैं कि किसी वास्तविक project में इन्हें बढ़ाना उचित है, क्योंकि हर पाँच annotations पर retraining उस model पर compute खर्च करती है जो मुश्किल से बदला है।
पूर्ण कॉन्फ़िगरेशन
active_learning:
enabled: true
schema_names:
- sentiment
min_annotations_per_instance: 1
min_instances_for_training: 20
update_frequency: 50
max_instances_to_reorder: 1000
# How disagreement between annotators resolves into one training label
resolution_strategy: majority_vote
# Fraction of the queue left in random order, so the model does not
# only ever see what it already found interesting
random_sample_percent: 0.2
classifier:
name: sklearn.linear_model.LogisticRegression
hyperparameters:
C: 1.0
max_iter: 1000
vectorizer:
name: sklearn.feature_extraction.text.TfidfVectorizer
hyperparameters:
max_features: 5000
ngram_range: [1, 2]
query_strategy: uncertainty
model_persistence:
enabled: true
save_directory: "models/"
retention_count: 5Nested classifier, vectorizer और model_persistence blocks ही documented रूप हैं, और potato validate --strict इन्हीं को पहचानता है। पहले दो के sub-keys name और hyperparameters हैं, और तीसरे के enabled, save_directory और retention_count। किसी दूसरे sub-key नाम वाला block बिना किसी चेतावनी के अनदेखा कर दिया जाता है, और run चुपचाप defaults पर लौट आता है।
Query Strategies
| Strategy | विवरण |
|---|---|
uncertainty | वे instances जिन पर model सबसे कम आश्वस्त है। यह default है |
diversity | वे instances जो अब तक annotate किए गए डेटा से सबसे कम मिलते-जुलते हैं |
badge | Batch Active learning by Diverse Gradient Embeddings |
bald | Bayesian Active Learning by Disagreement |
hybrid | uncertainty और diversity का भारित (weighted) संयोजन |
active_learning:
query_strategy: uncertaintyकोई अपरिचित strategy नाम boot को विफल करने के बजाय एक warning के साथ uncertainty पर लौट आता है, इसलिए यदि किसी strategy का कोई असर नहीं दिखता तो log जाँचें।
Hybrid और BALD को ट्यून करना
hybrid का default 70% uncertainty और 30% diversity है:
active_learning:
query_strategy: hybrid
hybrid_weights:
uncertainty: 0.7
diversity: 0.3bald एक छोटा ensemble प्रशिक्षित करता है और उसके भीतर की असहमति के आधार पर rank करता है:
active_learning:
query_strategy: bald
bald_params:
n_estimators: 5
bootstrap_fraction: 0.8Classifiers
Classifiers को उनके sklearn import path से नामित किया जाता है। Default sklearn.linear_model.LogisticRegression है।
| Classifier | Path | किसके लिए सबसे उपयुक्त | गति |
|---|---|---|---|
| Logistic Regression | sklearn.linear_model.LogisticRegression | अधिकांश text कार्य | तीव्र |
| Random Forest | sklearn.ensemble.RandomForestClassifier | Non-linear patterns | मध्यम |
| SVC | sklearn.svm.SVC | छोटे datasets | धीमा |
| Multinomial NB | sklearn.naive_bayes.MultinomialNB | सरल text classification | अत्यंत तीव्र |
Logistic regression, जो शुरुआत के लिए अनुशंसित है:
active_learning:
classifier:
name: sklearn.linear_model.LogisticRegression
hyperparameters:
C: 1.0
max_iter: 1000Random forest, जब निर्णय लगभग linear न हो:
active_learning:
classifier:
name: sklearn.ensemble.RandomForestClassifier
hyperparameters:
n_estimators: 100
max_depth: 10SVC को probabilities देने के लिए स्पष्ट रूप से कहना पड़ता है, क्योंकि uncertainty score उन्हीं पर निर्भर करता है:
active_learning:
classifier:
name: sklearn.svm.SVC
hyperparameters:
kernel: rbf
probability: trueNaive Bayes, जब accuracy के आख़िरी अंश से ज़्यादा गति मायने रखती हो:
active_learning:
classifier:
name: sklearn.naive_bayes.MultinomialNB
hyperparameters:
alpha: 1.0calibrate_probabilities default रूप से चालू रहता है। यह महत्वपूर्ण है, क्योंकि uncertainty sampling predicted probability के आधार पर rank करती है, और एक uncalibrated classifier उन items को भी तय मान लेता है जिन पर वह पूरे विश्वास से ग़लत है।
Vectorizers
Default sklearn.feature_extraction.text.TfidfVectorizer है।
TF-IDF, weighted features:
active_learning:
vectorizer:
name: sklearn.feature_extraction.text.TfidfVectorizer
hyperparameters:
max_features: 5000
ngram_range: [1, 2]
stop_words: englishसामान्य word counts:
active_learning:
vectorizer:
name: sklearn.feature_extraction.text.CountVectorizer
hyperparameters:
max_features: 3000
ngram_range: [1, 1]Hashing, उस vocabulary के लिए जो memory में रखने के लिए बहुत बड़ी हो:
active_learning:
vectorizer:
name: sklearn.feature_extraction.text.HashingVectorizer
hyperparameters:
n_features: 10000ngram_range को YAML list के रूप में लिखा जाता है और sklearn की अपेक्षित tuple में बदल दिया जाता है, इसलिए यहाँ [1, 2] सही है और इसके लिए किसी विशेष syntax की ज़रूरत नहीं।
Cold Start
किसी model के बनने से पहले अनिश्चितता मापने के लिए कुछ नहीं होता, इसलिए पहला batch बिना model के चुना जाता है:
active_learning:
cold_start_strategy: random
cold_start_batch_size: 20LLM-सहायता प्राप्त चयन
Cold-start अवधि के दौरान या classifier के साथ-साथ, एक LLM instances को स्कोर कर सकता है:
active_learning:
enabled: true
schema_names:
- sentiment
llm:
enabled: true
endpoint_type: vllm
base_url: http://localhost:8000/v1
model: meta-llama/Llama-3.2-3B-Instruct
confidence_method: verbalizedconfidence_method तय करता है कि confidence score कैसे प्राप्त किया जाए। यह चुनाव मायने रखता है, क्योंकि वही score चयन को संचालित करता है:
| Method | यह कैसे काम करता है | Trade-off |
|---|---|---|
verbalized | Model 1-10 के पैमाने पर अपना confidence स्वयं बताता है | हर जगह चलता है, पर कुछ models पर अविश्वसनीय |
logprobs | Token log probabilities से गणना की जाती है | सबसे अच्छी calibration, पर ऐसा endpoint चाहिए जो logprobs लौटाए |
consistency | एक ही instance को कई बार query किया जाता है और सहमति के आधार पर स्कोर किया जाता है | कहीं भी चलता है, पर प्रति instance N calls लगती हैं |
जब endpoint logprobs नहीं लौटाता, तो logprobs verbalized confidence पर लौट आता है।
Model Persistence
प्रशिक्षित models हर बार scratch से दोबारा बनाए जाने के बजाय restart के बाद भी बने रह सकते हैं:
active_learning:
model_persistence:
enabled: true
save_directory: "models/"
retention_count: 5retention_count का default 2 है, और यह तय करता है कि अधिकतम कितने saved models रखे जाएँ।
Database-आधारित persistence अब कॉन्फ़िगर नहीं की जा सकती। database_enabled और database_config keys हटा दी गईं, क्योंकि उनके पीछे की layer एक stub थी जो सफलता log करती थी पर कुछ भी store नहीं करती थी। Run history अब हमेशा दर्ज होती है और उसके लिए किसी कॉन्फ़िगरेशन की ज़रूरत नहीं। यदि कोई config अब भी ये दोनों keys रखता है, तो उन्हें अनदेखा किया जाता है।
कई Schemes
schema_names उन schemes की सूची है जिनके annotations से model प्रशिक्षित होता है। इसे सेट न करने पर यह project की labelable schemes पर default हो जाता है:
annotation_schemes:
- annotation_type: radio
name: sentiment
description: "What is the sentiment?"
labels: [Positive, Negative, Neutral]
- annotation_type: radio
name: topic
description: "What is the topic?"
labels: [Politics, Sports, Tech, Entertainment]
active_learning:
enabled: true
schema_names:
- sentiment
- topicपूर्ण कॉन्फ़िगरेशन उदाहरण
annotation_task_name: "Sentiment Analysis with Active Learning"
task_dir: "."
port: 8000
data_files:
- "data/reviews.json"
item_properties:
id_key: id
text_key: text
annotation_schemes:
- annotation_type: radio
name: sentiment
description: "What is the sentiment?"
labels:
- Positive
- Negative
- Neutral
sequential_key_binding: true
active_learning:
enabled: true
schema_names:
- sentiment
min_annotations_per_instance: 1
min_instances_for_training: 30
update_frequency: 50
max_instances_to_reorder: 500
random_sample_percent: 0.2
classifier:
name: sklearn.linear_model.LogisticRegression
hyperparameters:
C: 1.0
max_iter: 1000
vectorizer:
name: sklearn.feature_extraction.text.TfidfVectorizer
hyperparameters:
max_features: 5000
ngram_range: [1, 2]
query_strategy: uncertainty
model_persistence:
enabled: true
save_directory: "models/"
retention_count: 5
output_annotation_dir: "output/"
export_annotation_format: jsonl
user_config:
allow_all_users: trueAI Support के साथ संयोजन
Active learning तय करता है कि आगे क्या दिखाया जाए। AI support स्क्रीन पर जो भी है उसमें annotator की मदद करता है। दोनों स्वतंत्र हैं और साथ में इस्तेमाल किए जा सकते हैं:
active_learning:
enabled: true
schema_names:
- sentiment
min_instances_for_training: 30
ai_support:
enabled: true
endpoint_type: openai
ai_config:
model: gpt-4o-mini
api_key: ${OPENAI_API_KEY}
max_tokens: 800
include:
all: trueपरिणाम पढ़ते समय सावधान रहें। यदि model कोई label सुझाता है और annotator उसे स्वीकार कर लेता है, और उसी परिवार के model ने वह instance चुना था, तो अंत में मापी गई agreement आंशिक रूप से model की अपने आप से सहमति होती है।
निगरानी
Admin dashboard model accuracy, training cycles की संख्या, अनिश्चितता का वितरण, और शेष instances की संख्या दिखाता है। इस तक पहुँचने के लिए admin key या view_admin_dashboard वाली role चाहिए।
सर्वोत्तम प्रथाएँ
पहले एक baseline एकत्र करें
खाली सेट पर कुछ भी प्रशिक्षित नहीं किया जा सकता, और बीस annotations पर प्रशिक्षित model ज़्यादातर noise को ही पुनः क्रमबद्ध करता है:
active_learning:
min_instances_for_training: 50Class संतुलन पर नज़र रखें
Uncertainty sampling decision boundary पर केंद्रित रहती है, जिससे label वितरण corpus से अलग हो जाता है। Model प्रशिक्षित करने के लिए यह ठीक है, पर यदि आप annotate किए गए sample को डेटा के विवरण के रूप में रिपोर्ट करते हैं तो यह भ्रामक है। random_sample_percent इसी कारण queue के एक हिस्से को निष्पक्ष रखता है।
बहुत बार retrain न करें
active_learning:
update_frequency: 100Restart के बाद भी models रखें
active_learning:
model_persistence:
enabled: true
save_directory: "models/"समस्या निवारण
Training कभी शुरू नहीं होती
जाँचें कि annotations min_instances_for_training तक पहुँच गए हैं, और हर class का कम से कम एक उदाहरण मौजूद है। केवल एक class वाले training set पर classifier fit नहीं किया जा सकता।
पुनः क्रमण का कोई असर नहीं दिखता
Log में किसी अज्ञात query_strategy की जाँच करें, जो चुपचाप uncertainty पर लौट आती है। पुष्टि करें कि enabled: true है, और schema_names उन्हीं schemes के नाम देता है जो वास्तव में मौजूद हैं।
बड़े pool के साथ धीमा प्रदर्शन
max_instances_to_reorder कम करें, update_frequency बढ़ाएँ, या बहुत बड़ी vocabulary के लिए HashingVectorizer पर जाएँ।
आगे पढ़ें
- AI सपोर्ट - annotation के दौरान LLM सहायता
- कार्य आवंटन - अन्य assignment strategies
- एडमिन डैशबोर्ड - training loop की निगरानी
- Diversity Ordering - classifier के बिना embedding-आधारित क्रमण
कार्यान्वयन विवरण के लिए, स्रोत दस्तावेज़ देखें।