This is a classifier for evaluating mathematical reasoning and deduction in web pages, fine-tuned from
intfloat/multilingual-e5-small. It was developed to filter and curate mathematical content from web datasets and was trained on 1M annotations generated by
LLama3-70B-instruct for web samples from Common Crawl, which were extracted using the
OpenWebMath text extraction pipeline. To ensure a balanced dataset, we upsampled pages containing mathematical content in the annotations, using a preliminary math classifier on 5M samples.
We used this classifier to build
FineMath dataset.
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3tokenizer = AutoTokenizer.from_pretrained("HuggingFaceTB/finemath-classifier")
4model = AutoModelForSequenceClassification.from_pretrained("HuggingFaceTB/finemath-classifier")
5
6text = "This is a test sentence."
7inputs = tokenizer(text, return_tensors="pt", padding="longest", truncation=True)
8outputs = model(**inputs)
9logits = outputs.logits.squeeze(-1).float().detach().numpy()
10score = logits.item()
11result = {
12 "text": text,
13 "score": score,
14 "int_score": int(round(max(0, min(score, 5)))),
15}
16
17print(result)
18# {'text': 'This is a test sentence.', 'score': 0.07964489609003067, 'int_score': 0}
The classifier was trained on 1M pairs of web samples and their scores from 0 to 5, generated by Llama3. The samples were annotated based on their usefulness for studying mathematics with 0 being not educational or containing matematical content and 5 being outstanding for mathetmatics education.
We added a classification head with a single regression output to
intfloat/multilingual-e5-small and trained the model for 20 epochs with a learning rate of 3e-4. During training, the embedding and encoder layers were frozen to focus on the classification head. The model achieved an F1 score of 87% when converted to a binary classifier using a score threshold of 3.