Instructions to use peter2000/laya-vulnerability-groups-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use peter2000/laya-vulnerability-groups-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="peter2000/laya-vulnerability-groups-v2")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("peter2000/laya-vulnerability-groups-v2", device_map="auto") - Laya
How to use peter2000/laya-vulnerability-groups-v2 with Laya:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Pass HF_TOKEN to snapshot_download calls (authenticated resolve path)
Browse files- eval_full.py +5 -4
eval_full.py
CHANGED
|
@@ -22,6 +22,7 @@ import laya
|
|
| 22 |
BASE_MODEL_ID = "convaiinnovations/laya"
|
| 23 |
FT_REPO = "peter2000/laya-vulnerability-groups-v2"
|
| 24 |
SETFIT_REPO = "peter2000/setfit-vulnerability-groups"
|
|
|
|
| 25 |
PARQUET_URL = "https://huggingface.co/datasets/GIZ/vulnerability_training_data_full/resolve/refs%2Fconvert%2Fparquet/default/train/0000.parquet"
|
| 26 |
LABELS = [
|
| 27 |
"Agricultural communities", "Coastal communities", "Ethnic, racial or other minorities",
|
|
@@ -111,7 +112,7 @@ def main():
|
|
| 111 |
results = {}
|
| 112 |
|
| 113 |
print("== laya v2 fine-tuned ==", flush=True)
|
| 114 |
-
ft_dir = snapshot_download(FT_REPO, ignore_patterns=["*.py"])
|
| 115 |
agent = laya.load(ft_dir, device=device)
|
| 116 |
m = eval_agent(agent, X_te, Y_te)
|
| 117 |
results["laya_v2_fine_tuned"] = m
|
|
@@ -120,7 +121,7 @@ def main():
|
|
| 120 |
torch.cuda.empty_cache()
|
| 121 |
|
| 122 |
print("== laya base zero-shot (v2 climate-context instructions) ==", flush=True)
|
| 123 |
-
base_dir = snapshot_download(BASE_MODEL_ID, ignore_patterns=["multilingual/*", "typed-decisions/*", "assets/*", "eval/*", "*.py"])
|
| 124 |
_fix_tokenizer_config(base_dir)
|
| 125 |
agent = laya.load(base_dir, device=device)
|
| 126 |
m = eval_agent(agent, X_te, Y_te)
|
|
@@ -131,7 +132,7 @@ def main():
|
|
| 131 |
|
| 132 |
print("== setfit ==", flush=True)
|
| 133 |
from setfit import SetFitModel
|
| 134 |
-
sf = SetFitModel.from_pretrained(SETFIT_REPO)
|
| 135 |
t0 = time.time()
|
| 136 |
P = np.asarray(sf.predict_proba(X_te))
|
| 137 |
m = evaluate_full(Y_te, P)
|
|
@@ -145,7 +146,7 @@ def main():
|
|
| 145 |
"split": "train_test_split(random_state=42, test_size=0.2, stratify=min(n_labels,3)); n_test=95",
|
| 146 |
"models": results,
|
| 147 |
}
|
| 148 |
-
api = HfApi(token=
|
| 149 |
api.upload_file(
|
| 150 |
path_or_fileobj=json.dumps(out, indent=2).encode(),
|
| 151 |
path_in_repo="metrics_full.json",
|
|
|
|
| 22 |
BASE_MODEL_ID = "convaiinnovations/laya"
|
| 23 |
FT_REPO = "peter2000/laya-vulnerability-groups-v2"
|
| 24 |
SETFIT_REPO = "peter2000/setfit-vulnerability-groups"
|
| 25 |
+
TOKEN = os.environ.get("HF_TOKEN")
|
| 26 |
PARQUET_URL = "https://huggingface.co/datasets/GIZ/vulnerability_training_data_full/resolve/refs%2Fconvert%2Fparquet/default/train/0000.parquet"
|
| 27 |
LABELS = [
|
| 28 |
"Agricultural communities", "Coastal communities", "Ethnic, racial or other minorities",
|
|
|
|
| 112 |
results = {}
|
| 113 |
|
| 114 |
print("== laya v2 fine-tuned ==", flush=True)
|
| 115 |
+
ft_dir = snapshot_download(FT_REPO, ignore_patterns=["*.py"], token=TOKEN)
|
| 116 |
agent = laya.load(ft_dir, device=device)
|
| 117 |
m = eval_agent(agent, X_te, Y_te)
|
| 118 |
results["laya_v2_fine_tuned"] = m
|
|
|
|
| 121 |
torch.cuda.empty_cache()
|
| 122 |
|
| 123 |
print("== laya base zero-shot (v2 climate-context instructions) ==", flush=True)
|
| 124 |
+
base_dir = snapshot_download(BASE_MODEL_ID, ignore_patterns=["multilingual/*", "typed-decisions/*", "assets/*", "eval/*", "*.py"], token=TOKEN)
|
| 125 |
_fix_tokenizer_config(base_dir)
|
| 126 |
agent = laya.load(base_dir, device=device)
|
| 127 |
m = eval_agent(agent, X_te, Y_te)
|
|
|
|
| 132 |
|
| 133 |
print("== setfit ==", flush=True)
|
| 134 |
from setfit import SetFitModel
|
| 135 |
+
sf = SetFitModel.from_pretrained(SETFIT_REPO, token=TOKEN)
|
| 136 |
t0 = time.time()
|
| 137 |
P = np.asarray(sf.predict_proba(X_te))
|
| 138 |
m = evaluate_full(Y_te, P)
|
|
|
|
| 146 |
"split": "train_test_split(random_state=42, test_size=0.2, stratify=min(n_labels,3)); n_test=95",
|
| 147 |
"models": results,
|
| 148 |
}
|
| 149 |
+
api = HfApi(token=TOKEN)
|
| 150 |
api.upload_file(
|
| 151 |
path_or_fileobj=json.dumps(out, indent=2).encode(),
|
| 152 |
path_in_repo="metrics_full.json",
|