CoolFace
Modelpublic

faodl/agri-vegetable_oils-classifier

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
Model Card

AMIS Commodity Classifier

This model repository contains artifacts from an AMIS commodity relevance classifier training run. It includes the Transformer model, any configured TF-IDF or sentence-embedding baselines, prediction files, and the training report.

  • —Dataset: faodl/amis-agri-vegetable_oils
  • —Dataset subset: ``
  • —Dataset revision: main
  • —Text column: chunk_text
  • —Label column: label
  • —Transformer: FacebookAI/xlm-roberta-base
  • —Generated at: 2026-06-09T16:39:33.521615+00:00

Dataset Summary

SplitRowsLabel 0Label 1Unique groupsMean text length
train5382404013422395706.0
validation1186900286513711.4
test1082847235514699.9

Threshold Comparison on Validation Split

Validation metrics document threshold selection and tuning behavior; test metrics remain the primary estimate of out-of-sample performance.

ModelThresholdAccuracyPrecisionRecallF1ROC AUCAverage precision
logistic_tfidf0.5000.8790.7380.7690.7530.9290.804
logistic_tfidf0.4860.8800.7320.7940.7620.9290.804
xgboost_tfidf0.5000.8650.7970.5910.6790.9260.816
xgboost_tfidf0.3570.8820.7630.7410.7520.9260.816
embedding-logisticsentenceembeddings0.5000.8470.6320.8810.7360.9250.802
embedding-logisticsentenceembeddings0.6200.8710.7110.7830.7450.9250.802
embedding-svmsentenceembeddings0.5000.8530.7670.5630.6490.9180.787
embedding-svmsentenceembeddings0.3570.8650.6850.8150.7440.9180.787
embedding-lightgbmsentenceembeddings0.5000.8810.7600.7410.7500.9300.829
embedding-lightgbmsentenceembeddings0.3180.8790.7230.8040.7620.9300.829
transformer0.5000.8960.7620.8290.7940.9400.872
transformer0.6250.9100.8160.8080.8120.9400.872

Threshold Comparison on Test Split

ModelThresholdAccuracyPrecisionRecallF1ROC AUCAverage precision
logistic_tfidf0.5000.8960.7660.7530.7600.9370.817
logistic_tfidf0.4860.8960.7560.7660.7610.9370.817
xgboost_tfidf0.5000.8780.7720.6210.6890.9230.785
xgboost_tfidf0.3570.8820.7380.7060.7220.9230.785
embedding-logisticsentenceembeddings0.5000.8350.5830.8340.6870.9190.763
embedding-logisticsentenceembeddings0.6200.8570.6480.7450.6930.9190.763
embedding-svmsentenceembeddings0.5000.8710.7680.5790.6600.9080.758
embedding-svmsentenceembeddings0.3570.8410.6110.7400.6690.9080.758
embedding-lightgbmsentenceembeddings0.5000.8790.7450.6720.7070.9210.793
embedding-lightgbmsentenceembeddings0.3180.8720.6890.7530.7200.9210.793
transformer0.5000.8910.7410.7660.7530.9300.820
transformer0.6250.8940.7590.7490.7540.9300.820

Confusion Matrices on Test Split

Rows are true labels and columns are predicted labels.

logistic_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79354
RELEVANT58177

logistic_tfidf at threshold 0.486

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT78958
RELEVANT55180

xgboost_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT80443
RELEVANT89146

xgboost_tfidf at threshold 0.357

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT78859
RELEVANT69166

embedding-logisticsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT707140
RELEVANT39196

embedding-logisticsentenceembeddings at threshold 0.620

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT75295
RELEVANT60175

embedding-svmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT80641
RELEVANT99136

embedding-svmsentenceembeddings at threshold 0.357

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT736111
RELEVANT61174

embedding-lightgbmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79354
RELEVANT77158

embedding-lightgbmsentenceembeddings at threshold 0.318

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT76780
RELEVANT58177

transformer at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT78463
RELEVANT55180

transformer at threshold 0.625

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79156
RELEVANT59176

Validation-Tuned Thresholds

  • —logistic_tfidf: threshold 0.486 (validation F1 0.762); test F1 change vs 0.5: +0.001.
  • —xgboost_tfidf: threshold 0.357 (validation F1 0.752); test F1 change vs 0.5: +0.033.
  • —embedding-logistic_sentence_embeddings: threshold 0.620 (validation F1 0.745); test F1 change vs 0.5: +0.007.
  • —embedding-svm_sentence_embeddings: threshold 0.357 (validation F1 0.744); test F1 change vs 0.5: +0.009.
  • —embedding-lightgbm_sentence_embeddings: threshold 0.318 (validation F1 0.762); test F1 change vs 0.5: +0.013.
  • —transformer: threshold 0.625 (validation F1 0.812); test F1 change vs 0.5: +0.001.

Artifacts

  • —logistic_tfidf: /content/agri-vegetable_oils-classifier/baselines/logistic
  • —xgboost_tfidf: /content/agri-vegetable_oils-classifier/baselines/xgboost
  • —embedding-logistic_sentence_embeddings: /content/agri-vegetable_oils-classifier/baselines/embedding-logistic
  • —embedding-svm_sentence_embeddings: /content/agri-vegetable_oils-classifier/baselines/embedding-svm
  • —embedding-lightgbm_sentence_embeddings: /content/agri-vegetable_oils-classifier/baselines/embedding-lightgbm
  • —transformer: /content/agri-vegetable_oils-classifier/transformer

Inference

Install the runtime dependencies:

bash
pip install transformers torch huggingface_hub pandas joblib scikit-learn xgboost lightgbm

Transformer

python
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

MODEL_ID = "faodl/agri-vegetable_oils-classifier"

texts = [
    "Rice export prices increased after new procurement rules were announced.",
    "The finance ministry released its monthly fuel tax bulletin.",
]

tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, subfolder="transformer")
model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID, subfolder="transformer")
threshold = float(getattr(model.config, "threshold", 0.5))

encoded = tokenizer(
    texts,
    truncation=True,
    padding=True,
    max_length=256,
    return_tensors="pt",
)

with torch.no_grad():
    logits = model(**encoded).logits
    probabilities = torch.softmax(logits, dim=-1)[:, 1].tolist()

for text, probability in zip(texts, probabilities):
    label = model.config.id2label[int(probability >= threshold)]
    print({"text": text, "probability_positive": probability, "label": label})

TF-IDF Baselines

Available baseline names in this run: "logistic", "xgboost".

python
import json
import joblib
from huggingface_hub import hf_hub_download

MODEL_ID = "faodl/agri-vegetable_oils-classifier"
BASELINE = "logistic"

texts = [
    "Maize production forecasts were revised after delayed rains.",
    "The central bank published new exchange rate statistics.",
]

model_path = hf_hub_download(
    repo_id=MODEL_ID,
    repo_type="model",
    filename=f"baselines/{BASELINE}/{BASELINE}_tfidf.joblib",
)
report_path = hf_hub_download(
    repo_id=MODEL_ID,
    repo_type="model",
    filename="report.json",
)

pipeline = joblib.load(model_path)
with open(report_path, encoding="utf-8") as handle:
    report = json.load(handle)

threshold = next(
    result["validation_best_threshold"]["threshold"]
    for result in report["results"]
    if result["model_type"] == f"{BASELINE}_tfidf"
)

probabilities = pipeline.predict_proba(texts)[:, 1]
for text, probability in zip(texts, probabilities):
    label = "RELEVANT" if probability >= threshold else "NOT_RELEVANT"
    print({"text": text, "probability_positive": float(probability), "label": label})

Sentence-Embedding Baselines

Available embedding baseline names in this run: "embedding-logistic", "embedding-svm", "embedding-lightgbm".

python
import joblib
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModel, AutoTokenizer

MODEL_ID = "faodl/agri-vegetable_oils-classifier"
BASELINE = "embedding-logistic"

texts = [
    "Wheat export inspections rose as demand from importers increased.",
    "The sports ministry announced a new stadium renovation plan.",
]

model_path = hf_hub_download(
    repo_id=MODEL_ID,
    repo_type="model",
    filename=f"baselines/{BASELINE}/{BASELINE}.joblib",
)
artifact = joblib.load(model_path)
tokenizer = AutoTokenizer.from_pretrained(artifact["embedding_model_name"])
encoder = AutoModel.from_pretrained(artifact["embedding_model_name"])
encoder.eval()

encoded_batches = []
batch_size = artifact.get("embedding_batch_size", 64)
for start in range(0, len(texts), batch_size):
    batch_texts = texts[start : start + batch_size]
    inputs = tokenizer(
        batch_texts,
        padding=True,
        truncation=True,
        max_length=artifact.get("embedding_max_length", 256),
        return_tensors="pt",
    )
    with torch.no_grad():
        outputs = encoder(**inputs)
    token_embeddings = outputs.last_hidden_state
    attention_mask = inputs["attention_mask"].unsqueeze(-1).to(token_embeddings.dtype)
    embeddings = (token_embeddings * attention_mask).sum(dim=1)
    embeddings = embeddings / attention_mask.sum(dim=1).clamp(min=1e-9)
    if artifact.get("normalize_embeddings", True):
        embeddings = torch.nn.functional.normalize(embeddings, p=2, dim=1)
    encoded_batches.append(embeddings)
embeddings = torch.cat(encoded_batches).numpy()
probabilities = artifact["classifier"].predict_proba(embeddings)[:, 1]
threshold = artifact["validation_best_threshold"]["threshold"]

for text, probability in zip(texts, probabilities):
    label = "RELEVANT" if probability >= threshold else "NOT_RELEVANT"
    print({"text": text, "probability_positive": float(probability), "label": label})

Files

  • —REPORT.md: Markdown report for this training run.
  • —report.json: Machine-readable report containing metrics and thresholds.
  • —transformer/: Fine-tuned Transformer artifacts, when Transformer training is enabled.
  • —baselines/: TF-IDF and sentence-embedding baseline artifacts, when baseline training is enabled.
  • —*/validation_predictions.csv and */test_predictions.csv: Split-level predictions.