CoolFace
Modelpublic

faodl/agri-soybeans-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-soybeans
  • Dataset subset: ``
  • Text column: chunk_text
  • Label column: label
  • Transformer: distilbert/distilbert-base-multilingual-cased
  • Generated at: 2026-05-19T20:13:44.207534+00:00

Dataset Summary

SplitRowsLabel 0Label 1Unique groupsMean text length
train474538608852244702.4
validation1034782252481710.3
test1074889185482708.6

Threshold Comparison on Test Split

ModelThresholdAccuracyPrecisionRecallF1ROC AUCAverage precision
logistic_tfidf0.5000.9440.8050.8920.8460.9670.914
logistic_tfidf0.4540.9410.7850.9080.8420.9670.914
xgboost_tfidf0.5000.9540.8950.8320.8630.9640.896
xgboost_tfidf0.5490.9550.9050.8270.8640.9640.896
embedding-logisticsentenceembeddings0.5000.9390.7530.9570.8430.9880.951
embedding-logisticsentenceembeddings0.6470.9540.8370.9140.8730.9880.951
embedding-svmsentenceembeddings0.5000.9570.8840.8650.8740.9880.949
embedding-svmsentenceembeddings0.3790.9550.8480.9030.8740.9880.949
embedding-lightgbmsentenceembeddings0.5000.9590.8940.8650.8790.9850.950
embedding-lightgbmsentenceembeddings0.4290.9590.8900.8700.8800.9850.950
transformer0.5000.9540.8820.8490.8650.9760.929
transformer0.4930.9550.8830.8540.8680.9760.929

Confusion Matrices on Test Split

Rows are true labels and columns are predicted labels.

logistic_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT84940
RELEVANT20165

logistic_tfidf at threshold 0.454

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT84346
RELEVANT17168

xgboost_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT87118
RELEVANT31154

xgboost_tfidf at threshold 0.549

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT87316
RELEVANT32153

embedding-logisticsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT83158
RELEVANT8177

embedding-logisticsentenceembeddings at threshold 0.647

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT85633
RELEVANT16169

embedding-svmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT86821
RELEVANT25160

embedding-svmsentenceembeddings at threshold 0.379

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT85930
RELEVANT18167

embedding-lightgbmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT87019
RELEVANT25160

embedding-lightgbmsentenceembeddings at threshold 0.429

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT86920
RELEVANT24161

transformer at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT86821
RELEVANT28157

transformer at threshold 0.493

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT86821
RELEVANT27158

Validation-Tuned Thresholds

  • logistic_tfidf: threshold 0.454 (validation F1 0.870); test F1 change vs 0.5: -0.004.
  • xgboost_tfidf: threshold 0.549 (validation F1 0.900); test F1 change vs 0.5: +0.002.
  • embedding-logistic_sentence_embeddings: threshold 0.647 (validation F1 0.851); test F1 change vs 0.5: +0.031.
  • embedding-svm_sentence_embeddings: threshold 0.379 (validation F1 0.840); test F1 change vs 0.5: +0.000.
  • embedding-lightgbm_sentence_embeddings: threshold 0.429 (validation F1 0.847); test F1 change vs 0.5: +0.001.
  • transformer: threshold 0.493 (validation F1 0.924); test F1 change vs 0.5: +0.003.

Artifacts

  • logistic_tfidf: /content/agri-soybeans-classifier/baselines/logistic
  • xgboost_tfidf: /content/agri-soybeans-classifier/baselines/xgboost
  • embedding-logistic_sentence_embeddings: /content/agri-soybeans-classifier/baselines/embedding-logistic
  • embedding-svm_sentence_embeddings: /content/agri-soybeans-classifier/baselines/embedding-svm
  • embedding-lightgbm_sentence_embeddings: /content/agri-soybeans-classifier/baselines/embedding-lightgbm
  • transformer: /content/agri-soybeans-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-soybeans-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-soybeans-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-soybeans-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.