TajaKuzman commited on
Commit
d5ec83e
·
verified ·
1 Parent(s): a44a621

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +14 -27
README.md CHANGED
@@ -123,35 +123,22 @@ For reliable results, the classifier should be applied to documents of sufficien
123
  Use example:
124
 
125
  ```python
126
- from simpletransformers.classification import ClassificationModel
127
 
128
- model_args ={
129
- "num_train_epochs": 5,
130
- "learning_rate": 8e-06,
131
- "train_batch_size": 32,
132
- "max_seq_length": 512,
133
- "silent": True,
134
- }
 
 
 
135
 
136
- model = ClassificationModel(
137
- "xlmroberta", "classla/multilingual-IPTC-news-topic-classifier", use_cuda=True,
138
- args=model_args
139
-
140
- )
141
- predictions, logit_output = model.predict([
142
- "Slovenian handball team makes it to Paris Olympics semifinal Lille, 8 August - Slovenia defeated Norway 33:28 in the Olympic men's handball tournament in Lille late on Wednesday to advance to the semifinal where they will face Denmark on Friday evening. This is the best result the team has so far achieved at the Olympic Games and one of the best performances in the history of Slovenia's team sports squads.",
143
- """Moment dog sparks house fire after chewing power bank
144
- An indoor monitoring camera shows the moment a dog unintentionally caused a house fire after chewing on a portable lithium-ion battery power bank.
145
- In the video released by Tulsa Fire Department in Oklahoma, two dogs and a cat can be seen in the living room before a spark started the fire that spread within minutes.
146
- Tulsa Fire Department public information officer Andy Little said the pets escaped through a dog door, and according to local media the family was also evacuated safely.
147
- "Had there not been a dog door, they very well could have passed away," he told CBS affiliate KOTV.."""]
148
- )
149
-
150
- predictions
151
- # Output: array([3, 5])
152
-
153
- [model.config.id2label[i] for i in predictions]
154
- # Output: ['sport', 'disaster, accident and emergency incident']
155
 
156
  ```
157
 
 
123
  Use example:
124
 
125
  ```python
126
+ from transformers import pipeline
127
 
128
+ # Load a multi-class classification pipeline - if the model runs on CPU, comment out "device"
129
+ classifier = pipeline("text-classification", model="classla/multilingual-IPTC-news-topic-classifier", device=0)
130
+
131
+ # Example texts to classify
132
+ texts = [
133
+ """Slovenian handball team makes it to Paris Olympics semifinal Lille, 8 August - Slovenia defeated Norway 33:28 in the Olympic men's handball tournament in Lille late on Wednesday to advance to the semifinal where they will face Denmark on Friday evening. This is the best result the team has so far achieved at the Olympic Games and one of the best performances in the history of Slovenia's team sports squads.""",
134
+ """Moment dog sparks house fire after chewing power bank An indoor monitoring camera shows the moment a dog unintentionally caused a house fire after chewing on a portable lithium-ion battery power bank. In the video released by Tulsa Fire Department in Oklahoma, two dogs and a cat can be seen in the living room before a spark started the fire that spread within minutes. Tulsa Fire Department public information officer Andy Little said the pets escaped through a dog door, and according to local media the family was also evacuated safely. "Had there not been a dog door, they very well could have passed away," he told CBS affiliate KOTV."""]
135
+
136
+ # Classify the texts
137
+ results = classifier(texts)
138
 
139
+ # Output the results
140
+ for result in results:
141
+ print(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
  ```
144