mjpsm commited on
Commit
8723d13
·
verified ·
1 Parent(s): 2aae2e1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +38 -9
README.md CHANGED
@@ -55,19 +55,48 @@ README.md
55
  ```python
56
  from sentence_transformers import SentenceTransformer
57
  import xgboost as xgb
58
-
59
- embedder = SentenceTransformer("sentence_transformer_model")
60
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  booster = xgb.Booster()
62
- booster.load_model("checkin_or_not_classifier.json")
63
 
64
- def predict(text):
 
 
 
65
  emb = embedder.encode([text])
66
- pred = booster.predict(xgb.DMatrix(emb))[0]
67
- return ("CHECKIN" if pred >= 0.5 else "NOT_CHECKIN", float(pred))
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- label, score = predict("Today I worked on automation tasks.")
70
- print(label, score)
71
  ```
72
 
73
  ## 📘 Intended Use
 
55
  ```python
56
  from sentence_transformers import SentenceTransformer
57
  import xgboost as xgb
58
+ import numpy as np
59
+ from huggingface_hub import hf_hub_download
60
+
61
+ # ----------------------------------------------------
62
+ # 1. Load the embedding model (must be downloaded locally)
63
+ # ----------------------------------------------------
64
+ # Users must install: pip install sentence-transformers
65
+ embedder = SentenceTransformer("all-MiniLM-L6-v2")
66
+
67
+ # ----------------------------------------------------
68
+ # 2. Download your XGBoost model from HuggingFace Hub
69
+ # ----------------------------------------------------
70
+ model_path = hf_hub_download(
71
+ repo_id="mjpsm/checkin_or_not_model",
72
+ filename="checkin_or_not_classifier.json"
73
+ )
74
+
75
+ # Load the model
76
  booster = xgb.Booster()
77
+ booster.load_model(model_path)
78
 
79
+ # ----------------------------------------------------
80
+ # 3. Prediction function
81
+ # ----------------------------------------------------
82
+ def predict(text: str):
83
  emb = embedder.encode([text])
84
+ dmatrix = xgb.DMatrix(emb)
85
+
86
+ score = float(booster.predict(dmatrix)[0])
87
+ label = "CHECKIN" if score >= 0.5 else "NOT_CHECKIN"
88
+
89
+ return {"label": label, "score": score}
90
+
91
+
92
+ # ----------------------------------------------------
93
+ # 4. Example usage
94
+ # ----------------------------------------------------
95
+ example = "Today I worked on improving the automation workflow."
96
+ result = predict(example)
97
+
98
+ print(result)
99
 
 
 
100
  ```
101
 
102
  ## 📘 Intended Use