Run this model with HF Jobs
Run mahmudnosirov/context-extractor on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/mahmudnosirov/context-extractor. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/mahmudnosirov/context-extractor on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use mahmudnosirov/context-extractor with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mahmudnosirov/context-extractor with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="mahmudnosirov/context-extractor")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("mahmudnosirov/context-extractor") model = AutoModelForTokenClassification.from_pretrained("mahmudnosirov/context-extractor", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Context Extractor
Give it a search query and a text, and it picks out the related parts to the query. Use it to cut long texts down before handing them to an LLM.
| Size | 6 layers, hidden size 384, 107M parameters (96M of them the 250K-token vocabulary), 214 MB in float16 |
| Input | <s> query </s></s> text </s>, at most 512 tokens; the query is cut to 64 tokens. A longer text is read in several windows, each with the query in front. |
| Output | One logit per token. A sentence's score is the mean over its tokens: above 0 means it matters to the query. |
| Speed | 10 times faster than XLM-R Large |
Example
Query: айфон 17 нархи
Text: The model's picks are highlighted:
Bugungi asosiy yangiliklar.
Toshkentdagi «Yangi O‘zbekiston» bog‘ida yangi favvora ochildi.
Samarqandda xalqaro turizm forumi bo‘lib o‘tdi, unda 40 dan ortiq davlat vakillari ishtirok etdi.
«Paxtakor» jamoasi Superligada «Navbahor»ni 2:1 hisobida mag‘lub etdi.
Farg‘ona viloyatida yangi to‘qimachilik korxonasi ishga tushirildi va 500 ga yaqin ish o‘rni yaratildi.
Apple kompaniyasining iPhone 17 smartfoni O‘zbekistonda sotuvga chiqdi: uning narxi 14 million so‘mdan boshlanadi.
Toshkent metropoliteni Yunusobod yo‘nalishida ikkita yangi bekat qurilishini yakunladi.
Toshkentda yangi bolalar bog‘chasi foydalanishga topshirildi.
Buxoroda qadimiy madrasa ta’mirdan so‘ng tashrif buyuruvchilar uchun qayta ochildi.
Andijon viloyatida paxta hosili 1,2 million tonnadan oshdi.
Navoiy shahrida yangi sport majmuasi qurilishi boshlandi.
Qoraqalpog‘istonda yangi suv quvuri 30 ming aholini toza ichimlik suvi bilan ta’minlaydi.
Do‘konlarda iPhone 17 Pro modeli 18 million so‘mga sotilmoqda.
Toshkent xalqaro aeroportida yo‘lovchilar oqimi o‘tgan yilga nisbatan 15 foizga oshdi.
Universitetlarda qishki ta’til 25-yanvardan boshlanadi.
Namanganda gul festivali bo‘lib o‘tdi va unga 20 mingdan ortiq mehmon tashrif buyurdi.
Xorazmda 200 o‘rinli yangi mehmonxona qurildi.
Surxondaryoda limon yetishtiradigan yangi issiqxona ishga tushdi.
Toshkentda «Yil o‘qituvchisi» tanlovi g‘oliblari taqdirlandi.
Jizzaxda yangi avtomobil yo‘li qurilishi yakunlandi.
Toshkent viloyatida 300 o‘rinli yangi shifoxona qurilishi boshlandi.
Olmaliq kon-metallurgiya kombinati yangi sexini ishga tushirdi.
Qashqadaryoda fermerlar uchun yangi o‘g‘it ombori ochildi.
Ertaga Toshkentda havo bulutli bo‘lib, harorat +5 darajagacha ko‘tariladi.
The model kept 2 of the 24 sentences, 176 of 1,709 characters (10%). They are the two about the iPhone 17's price, which scored above 0. Every other sentence scored less than 0.
Usage
predict.py in this repository splits a text into sentences, reads it in windows and averages the token scores:
from predict import load, score
tok, model = load() # downloads the model; float16 on a GPU, float32 on the CPU
text = open("text.txt", encoding="utf-8").read()
for start, end, s in score("toshkent metro yangi bekatlar", text, tok, model):
print(f"{s:6.2f} {text[start:end]}")
From the command line: python predict.py "toshkent metro yangi bekatlar" text.txt. Your own parts can be passed
as score(..., parts=[(start, end), ...]).
With transformers alone, for a text that fits in one window:
import torch
from transformers import AutoModelForTokenClassification, AutoTokenizer
name = "mahmudnosirov/context-extractor"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForTokenClassification.from_pretrained(name, dtype=torch.float32).eval()
enc = tok(query, text, return_tensors="pt", return_offsets_mapping=True, truncation="only_second", max_length=512)
offsets = enc.pop("offset_mapping")
with torch.no_grad():
token_scores = model(**enc).logits[0, :, 0] # one score per token; average them over each sentence
The model was trained on sentences of at most about 150 characters, with very short pieces joined to their
neighbours; predict.py's splitter does the same.
Training
- Base: mMiniLMv2-L6-H384, distilled from XLM-R Large.
- Uzbek: one pass of masked-word training on 479M tokens of public Telegram and YouTube texts from Uzbekistan (uzbekistan-media-2025-2026: posts, group messages, comments, video titles, transcripts): Uzbek in Latin letters 51%, in Cyrillic letters 21.5%, Russian 27%.
- Sentence scores: 16.2M (query, text) pairs.
- 97,423 queries were written by Gemini from random seed texts: topics and names, in the same language as the text, in the other alphabet, in another language, misspelt or plain.
- The candidate texts for each query were found by meaning with multilingual-e5-large-instruct, among Telegram posts and group messages, YouTube titles and descriptions, comments, subtitles and voice-message transcripts.
- Each text was cut into parts of up to about 150 characters, and Gemini picked the parts that someone answering the query would use.
- Tokens of picked parts are labelled 1, tokens of the other parts 0, with binary cross-entropy per token. One epoch over 2.79B tokens: AdamW, learning rate 5e-5 (6% warm-up, then linear decay), weight decay 0.01, batches of 16,384 tokens, about 50 minutes on one RTX 5090.
Evaluation
300 queries held out from training, 66,178 (query, text) pairs, 389,681 parts, 60,352 of them picked by Gemini.
| Part AUC (picked vs not) | 0.919; the share of the query's words in the part: 0.637 |
| By query style | same language 0.930, other alphabet 0.926, other language 0.895, misspelt 0.938, plain 0.909 |
| By query kind | topics 0.917, names 0.924 |
| By text kind | channel posts 0.925, video titles and descriptions 0.907, comments 0.893, group messages 0.889, subtitles 0.863, voice-message transcripts 0.851 |
| Keeping the best-scored 10 / 20 / 30% of each text's parts | keeps 51 / 70 / 81% of the parts Gemini picked |
| Text level (its best part's score) | relevant vs unrelated texts AUC 0.990; any relation vs unrelated 0.932 |
Limitations
- The labels come from an LLM (Gemini), not from people, and the training queries were written by an LLM too: real users' queries may differ.
- Trained on public Telegram and YouTube texts from Uzbekistan; other kinds of text are untested.
- Scores are logits, not probabilities. 0 is the natural cut, but the right one depends on the use.
- Matching across languages is weaker than within one: part AUC 0.895 for queries in another language than the text, 0.930 in the same one.
- Subtitles and voice transcripts, often without punctuation, score worst.
- Downloads last month
- -