Update README.md
Browse files
README.md
CHANGED
@@ -34,22 +34,13 @@ You'll need to pip install transformers & maybe sentencepiece
|
|
34 |
|
35 |
### How to use
|
36 |
```python
|
37 |
-
from transformers import
|
38 |
-
|
39 |
-
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
40 |
model_name = 'Reggie/muppet-roberta-base-joke_detector'
|
41 |
max_seq_len = 510
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
hypothesis = ""
|
48 |
-
|
49 |
-
input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
|
50 |
-
output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
|
51 |
-
prediction = torch.softmax(output["logits"][0], -1).tolist()
|
52 |
-
is_joke = True if prediction[0] < prediction[1] else False
|
53 |
-
|
54 |
-
print(is_joke)
|
55 |
```
|
|
|
34 |
|
35 |
### How to use
|
36 |
```python
|
37 |
+
from transformers import pipeline
|
38 |
+
device = 0 if torch.cuda.is_available() else -1
|
|
|
39 |
model_name = 'Reggie/muppet-roberta-base-joke_detector'
|
40 |
max_seq_len = 510
|
41 |
|
42 |
+
pipe = pipeline(model=model_name, device=device, truncation=True, max_length=max_seq_len)
|
43 |
+
is_it_a_joke = """A nervous passenger is about to book a flight ticket, and he asks the airlines' ticket seller, "I hope your planes are safe. Do they have a good track record for safety?" The airline agent replies, "Sir, I can guarantee you, we've never had a plane that has crashed more than once." """
|
44 |
+
result = pipe(is_it_a_joke) # [{'label': 'LABEL_1', 'score': 0.7313136458396912}]
|
45 |
+
print('This is a joke') if result[0]['label'] == 'LABEL_1' else print('This is not a joke')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
```
|