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.
Rows are true labels and columns are predicted labels.
1import torch
2from transformers import AutoModelForSequenceClassification, AutoTokenizer
3
4MODEL_ID = "faodl/agri-trade-classifier"
5
6texts = [
7 "Rice export prices increased after new procurement rules were announced.",
8 "The finance ministry released its monthly fuel tax bulletin.",
9]
10
11tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, subfolder="transformer")
12model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID, subfolder="transformer")
13threshold = float(getattr(model.config, "threshold", 0.5))
14
15encoded = tokenizer(
16 texts,
17 truncation=True,
18 padding=True,
19 max_length=256,
20 return_tensors="pt",
21)
22
23with torch.no_grad():
24 logits = model(**encoded).logits
25 probabilities = torch.softmax(logits, dim=-1)[:, 1].tolist()
26
27for text, probability in zip(texts, probabilities):
28 label = model.config.id2label[int(probability >= threshold)]
29 print({"text": text, "probability_positive": probability, "label": label})
Available baseline names in this run: "logistic", "xgboost".
1import json
2import joblib
3from huggingface_hub import hf_hub_download
4
5MODEL_ID = "faodl/agri-trade-classifier"
6BASELINE = "logistic"
7
8texts = [
9 "Maize production forecasts were revised after delayed rains.",
10 "The central bank published new exchange rate statistics.",
11]
12
13model_path = hf_hub_download(
14 repo_id=MODEL_ID,
15 repo_type="model",
16 filename=f"baselines/{BASELINE}/{BASELINE}_tfidf.joblib",
17)
18report_path = hf_hub_download(
19 repo_id=MODEL_ID,
20 repo_type="model",
21 filename="report.json",
22)
23
24pipeline = joblib.load(model_path)
25with open(report_path, encoding="utf-8") as handle:
26 report = json.load(handle)
27
28threshold = next(
29 result["validation_best_threshold"]["threshold"]
30 for result in report["results"]
31 if result["model_type"] == f"{BASELINE}_tfidf"
32)
33
34probabilities = pipeline.predict_proba(texts)[:, 1]
35for text, probability in zip(texts, probabilities):
36 label = "RELEVANT" if probability >= threshold else "NOT_RELEVANT"
37 print({"text": text, "probability_positive": float(probability), "label": label})
Available embedding baseline names in this run: "embedding-logistic", "embedding-svm", "embedding-lightgbm".
1import joblib
2from huggingface_hub import hf_hub_download
3from sentence_transformers import SentenceTransformer
4
5MODEL_ID = "faodl/agri-trade-classifier"
6BASELINE = "embedding-logistic"
7
8texts = [
9 "Wheat export inspections rose as demand from importers increased.",
10 "The sports ministry announced a new stadium renovation plan.",
11]
12
13model_path = hf_hub_download(
14 repo_id=MODEL_ID,
15 repo_type="model",
16 filename=f"baselines/{BASELINE}/{BASELINE}.joblib",
17)
18artifact = joblib.load(model_path)
19embedding_model = SentenceTransformer(artifact["embedding_model_name"])
20embeddings = embedding_model.encode(
21 texts,
22 batch_size=artifact.get("embedding_batch_size", 64),
23 convert_to_numpy=True,
24 normalize_embeddings=artifact.get("normalize_embeddings", True),
25)
26probabilities = artifact["classifier"].predict_proba(embeddings)[:, 1]
27threshold = artifact["validation_best_threshold"]["threshold"]
28
29for text, probability in zip(texts, probabilities):
30 label = "RELEVANT" if probability >= threshold else "NOT_RELEVANT"
31 print({"text": text, "probability_positive": float(probability), "label": label})