chidamnat2002 commited on
Commit
3c6154f
·
verified ·
1 Parent(s): 78c7be7

Update README.md

Browse files

updated README.md

Files changed (1) hide show
  1. README.md +31 -4
README.md CHANGED
@@ -67,11 +67,38 @@ import torch
67
  model = AutoModelForSequenceClassification.from_pretrained("mozilla/content-multilabel-iab-classifier")
68
  tokenizer = AutoTokenizer.from_pretrained("mozilla/content-multilabel-iab-classifier")
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  text = "Discover the latest trends in AI and wearable technology."
71
- inputs = tokenizer(text, return_tensors="pt", truncation=True)
72
- outputs = model(**inputs)
73
- probs = torch.sigmoid(outputs.logits)
74
- predicted_labels = (probs > 0.5).int()
 
 
75
  ```
76
 
77
  📖 Citation
 
67
  model = AutoModelForSequenceClassification.from_pretrained("mozilla/content-multilabel-iab-classifier")
68
  tokenizer = AutoTokenizer.from_pretrained("mozilla/content-multilabel-iab-classifier")
69
 
70
+ label_list = [
71
+ 'inconclusive',
72
+ 'animals',
73
+ 'arts',
74
+ 'autos',
75
+ 'business',
76
+ 'career',
77
+ 'education',
78
+ 'fashion',
79
+ 'finance',
80
+ 'food',
81
+ 'government',
82
+ 'health',
83
+ 'hobbies',
84
+ 'home',
85
+ 'news',
86
+ 'realestate',
87
+ 'society',
88
+ 'sports',
89
+ 'tech',
90
+ 'travel'
91
+ ]
92
+ label2id = {label: idx for idx, label in enumerate(label_list)}
93
+ id2label = {idx: label for label, idx in label2id.items()}
94
+
95
  text = "Discover the latest trends in AI and wearable technology."
96
+
97
+ with torch.no_grad():
98
+ inputs = tokenizer(text, return_tensors="pt", truncation=True)
99
+ outputs = model(**inputs)
100
+ probs = torch.sigmoid(outputs.logits).squeeze().cpu().numpy()
101
+ predicted_labels = [(id2label[i], round(p, 3)) for i, p in enumerate(probs) if p >= 0.5]
102
  ```
103
 
104
  📖 Citation