Reggie commited on
Commit
5bb0510
1 Parent(s): a5757a2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +7 -16
README.md CHANGED
@@ -35,22 +35,13 @@ You'll need to pip install transformers & maybe sentencepiece
35
 
36
  ### How to use
37
  ```python
38
- from transformers import AutoTokenizer, AutoModelForSequenceClassification
39
- import torch, time
40
- device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
41
- model_name = 'Reggie/muppet-roberta-base-joke_detector'
42
  max_seq_len = 510
43
 
44
- tokenizer = AutoTokenizer.from_pretrained(model_name, model_max_length=max_seq_len)
45
- model = AutoModelForSequenceClassification.from_pretrained(model_name).to(device)
46
-
47
- premise = """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." """
48
- hypothesis = ""
49
-
50
- input = tokenizer(premise, hypothesis, truncation=True, return_tensors="pt")
51
- output = model(input["input_ids"].to(device)) # device = "cuda:0" or "cpu"
52
- prediction = torch.softmax(output["logits"][0], -1).tolist()
53
- is_joke = True if prediction[0] < prediction[1] else False
54
-
55
- print(is_joke)
56
  ```
 
35
 
36
  ### How to use
37
  ```python
38
+ from transformers import pipeline
39
+ device = 0 if torch.cuda.is_available() else -1
40
+ model_name = 'Reggie/DeBERTa-v3-base-joke_detector/'
 
41
  max_seq_len = 510
42
 
43
+ pipe = pipeline(model=model_name, device=device, truncation=True, max_length=max_seq_len)
44
+ 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." """
45
+ result = pipe(is_it_a_joke) # [{'label': 'LABEL_1', 'score': 0.7313136458396912}]
46
+ print('This is a joke') if result[0]['label'] == 'LABEL_1' else print('This is not a joke')
 
 
 
 
 
 
 
 
47
  ```