CoolFace
Modelpublic

faodl/agri-maize_corn-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-maize_corn
  • —Dataset subset: ``
  • —Dataset revision: main
  • —Text column: chunk_text
  • —Label column: label
  • —Transformer: FacebookAI/xlm-roberta-base
  • —Generated at: 2026-06-05T20:32:51.106165+00:00

Dataset Summary

SplitRowsLabel 0Label 1Unique groupsMean text length
train472438229022226702.9
validation1060843217477708.3
test1054819235478711.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.8960.7000.8620.7730.9290.841
logistic_tfidf0.5860.9150.7770.8200.7980.9290.841
xgboost_tfidf0.5000.9570.9130.8710.8920.9670.914
xgboost_tfidf0.3790.9580.9020.8940.8980.9670.914
embedding-logisticsentenceembeddings0.5000.8810.6490.9120.7590.9590.867
embedding-logisticsentenceembeddings0.7440.9230.8080.8160.8120.9590.867
embedding-svmsentenceembeddings0.5000.9130.8490.7000.7680.9550.858
embedding-svmsentenceembeddings0.4010.9140.7890.7930.7910.9550.858
embedding-lightgbmsentenceembeddings0.5000.9160.7910.8020.7960.9630.878
embedding-lightgbmsentenceembeddings0.1450.9160.7460.8940.8130.9630.878
transformer0.5000.9580.9130.8760.8940.9730.943
transformer0.3280.9590.9070.8940.9000.9730.943

Threshold Comparison on Test Split

ModelThresholdAccuracyPrecisionRecallF1ROC AUCAverage precision
logistic_tfidf0.5000.9100.7870.8170.8020.9530.863
logistic_tfidf0.5860.9150.8570.7400.7950.9530.863
xgboost_tfidf0.5000.9420.9140.8170.8630.9680.920
xgboost_tfidf0.3790.9480.8950.8680.8810.9680.920
embedding-logisticsentenceembeddings0.5000.8840.7040.8300.7620.9360.844
embedding-logisticsentenceembeddings0.7440.8960.8310.6680.7410.9360.844
embedding-svmsentenceembeddings0.5000.8940.8920.5960.7140.9320.842
embedding-svmsentenceembeddings0.4010.9020.8510.6810.7570.9320.842
embedding-lightgbmsentenceembeddings0.5000.9070.8700.6850.7670.9530.873
embedding-lightgbmsentenceembeddings0.1450.9010.7840.7700.7770.9530.873
transformer0.5000.9350.8920.8040.8460.9530.890
transformer0.3280.9350.8810.8170.8480.9530.890

Confusion Matrices on Test Split

Rows are true labels and columns are predicted labels.

logistic_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT76752
RELEVANT43192

logistic_tfidf at threshold 0.586

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79029
RELEVANT61174

xgboost_tfidf at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT80118
RELEVANT43192

xgboost_tfidf at threshold 0.379

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79524
RELEVANT31204

embedding-logisticsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT73782
RELEVANT40195

embedding-logisticsentenceembeddings at threshold 0.744

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT78732
RELEVANT78157

embedding-svmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT80217
RELEVANT95140

embedding-svmsentenceembeddings at threshold 0.401

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79128
RELEVANT75160

embedding-lightgbmsentenceembeddings at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79524
RELEVANT74161

embedding-lightgbmsentenceembeddings at threshold 0.145

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT76950
RELEVANT54181

transformer at threshold 0.500

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79623
RELEVANT46189

transformer at threshold 0.328

True / PredictedNOT_RELEVANTRELEVANT
NOT_RELEVANT79326
RELEVANT43192

Validation-Tuned Thresholds

  • —logistic_tfidf: threshold 0.586 (validation F1 0.798); test F1 change vs 0.5: -0.007.
  • —xgboost_tfidf: threshold 0.379 (validation F1 0.898); test F1 change vs 0.5: +0.018.
  • —embedding-logistic_sentence_embeddings: threshold 0.744 (validation F1 0.812); test F1 change vs 0.5: -0.021.
  • —embedding-svm_sentence_embeddings: threshold 0.401 (validation F1 0.791); test F1 change vs 0.5: +0.042.
  • —embedding-lightgbm_sentence_embeddings: threshold 0.145 (validation F1 0.813); test F1 change vs 0.5: +0.010.
  • —transformer: threshold 0.328 (validation F1 0.900); test F1 change vs 0.5: +0.002.

Artifacts

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