CoolFace
Modelpublic

faodl/agri-trade-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-trade-pri-sec
  • —Dataset subset: ``
  • —Text column: chunk_text
  • —Label column: label
  • —Transformer: FacebookAI/xlm-roberta-base
  • —Generated at: 2026-05-18T17:47:01.228362+00:00

Dataset Summary

SplitRowsLabel 0Label 1Unique groupsMean text length
train4799236324362483695.5
validation1009462547532698.1
test1017529488533694.6

Threshold Comparison on Test Split

ModelThresholdAccuracyPrecisionRecallF1ROC AUCAverage precision
logistic_tfidf0.5000.7380.7360.7090.7220.8380.815
logistic_tfidf0.3960.7440.6740.9040.7720.8380.815
xgboost_tfidf0.5000.7620.7860.6930.7360.8470.816
xgboost_tfidf0.3050.7520.6850.8950.7760.8470.816
embedding-logisticsentenceembeddings0.5000.7900.7500.8420.7930.8810.863
embedding-logisticsentenceembeddings0.3150.7710.6980.9220.7940.8810.863
embedding-svmsentenceembeddings0.5000.7880.7420.8550.7940.8830.865
embedding-svmsentenceembeddings0.4530.7960.7350.9000.8090.8830.865
embedding-lightgbmsentenceembeddings0.5000.7820.7440.8320.7850.8800.867
embedding-lightgbmsentenceembeddings0.1480.7590.6850.9220.7860.8800.867
transformer0.5000.8370.7860.9060.8420.9190.913
transformer0.3830.8370.7710.9390.8470.9190.913

Confusion Matrices on Test Split

Rows are true labels and columns are predicted labels.

logistic_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT405124
RELEVANT142346

logistic_tfidf at threshold 0.396

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT316213
RELEVANT47441

xgboost_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT43792
RELEVANT150338

xgboost_tfidf at threshold 0.305

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT328201
RELEVANT51437

embedding-logisticsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT392137
RELEVANT77411

embedding-logisticsentenceembeddings at threshold 0.315

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT334195
RELEVANT38450

embedding-svmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT384145
RELEVANT71417

embedding-svmsentenceembeddings at threshold 0.453

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT371158
RELEVANT49439

embedding-lightgbmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT389140
RELEVANT82406

embedding-lightgbmsentenceembeddings at threshold 0.148

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT322207
RELEVANT38450

transformer at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT409120
RELEVANT46442

transformer at threshold 0.383

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT393136
RELEVANT30458

Validation-Tuned Thresholds

  • —logistic_tfidf: threshold 0.396 (validation F1 0.811); test F1 change vs 0.5: +0.050.
  • —xgboost_tfidf: threshold 0.305 (validation F1 0.813); test F1 change vs 0.5: +0.040.
  • —embedding-logistic_sentence_embeddings: threshold 0.315 (validation F1 0.859); test F1 change vs 0.5: +0.001.
  • —embedding-svm_sentence_embeddings: threshold 0.453 (validation F1 0.861); test F1 change vs 0.5: +0.015.
  • —embedding-lightgbm_sentence_embeddings: threshold 0.148 (validation F1 0.866); test F1 change vs 0.5: +0.001.
  • —transformer: threshold 0.383 (validation F1 0.874); test F1 change vs 0.5: +0.005.

Artifacts

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

Inference

Install the runtime dependencies:

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

Transformer

python
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

MODEL_ID = "faodl/agri-trade-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-trade-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
from huggingface_hub import hf_hub_download
from sentence_transformers import SentenceTransformer

MODEL_ID = "faodl/agri-trade-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)
embedding_model = SentenceTransformer(artifact["embedding_model_name"])
embeddings = embedding_model.encode(
    texts,
    batch_size=artifact.get("embedding_batch_size", 64),
    convert_to_numpy=True,
    normalize_embeddings=artifact.get("normalize_embeddings", True),
)
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.