Update README.md
Browse files
README.md
CHANGED
@@ -22,33 +22,63 @@ WIP
|
|
22 |
|
23 |
## Example:
|
24 |
```
|
|
|
25 |
import torch
|
26 |
-
from transformers import pipeline
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
torch_dtype=torch.bfloat16,
|
32 |
-
device_map="
|
|
|
33 |
)
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
]
|
40 |
-
prompt = pipe.tokenizer.apply_chat_template(
|
41 |
-
messages,
|
42 |
-
tokenize=False,
|
43 |
-
add_generation_prompt=True,
|
44 |
-
)
|
45 |
-
res = pipe(
|
46 |
-
prompt,
|
47 |
-
max_new_tokens=256,
|
48 |
)
|
49 |
-
print(res[0]["generated_text"])
|
50 |
-
# <|prompt|>Why is drinking water so healthy?</s><|answer|> Drinking water is healthy for several reasons: [...]
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
```
|
53 |
|
54 |
-
## Output:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
## Example:
|
24 |
```
|
25 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer, StoppingCriteria
|
26 |
import torch
|
|
|
27 |
|
28 |
+
class MyStoppingCriteria(StoppingCriteria):
|
29 |
+
def __init__(self, target_sequence, prompt):
|
30 |
+
self.target_sequence = target_sequence
|
31 |
+
self.prompt=prompt
|
32 |
+
|
33 |
+
def __call__(self, input_ids, scores, **kwargs):
|
34 |
+
generated_text = tokenizer.decode(input_ids[0])
|
35 |
+
generated_text = generated_text.replace(self.prompt,'')
|
36 |
+
if self.target_sequence in generated_text:
|
37 |
+
return True
|
38 |
+
return False
|
39 |
+
|
40 |
+
def __len__(self):
|
41 |
+
return 1
|
42 |
+
|
43 |
+
def __iter__(self):
|
44 |
+
yield self
|
45 |
+
|
46 |
+
modelpath="aloobun/Cypher-Mini-1.8B"
|
47 |
+
|
48 |
+
model = AutoModelForCausalLM.from_pretrained(
|
49 |
+
modelpath,
|
50 |
torch_dtype=torch.bfloat16,
|
51 |
+
device_map="cuda",
|
52 |
+
trust_remote_code=True,
|
53 |
)
|
54 |
|
55 |
+
tokenizer = AutoTokenizer.from_pretrained(
|
56 |
+
modelpath,
|
57 |
+
trust_remote_code=True,
|
58 |
+
use_fast=False,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
)
|
|
|
|
|
60 |
|
61 |
+
prompt = "<|prompt|>Reflect on a time when you encountered a logical fallacy in an argument. How did you identify it, and what was the consequence?</s><|answer|>"
|
62 |
+
encoded_input = tokenizer(prompt, return_tensors='pt')
|
63 |
+
input_ids=encoded_input['input_ids'].cuda()
|
64 |
+
streamer = TextStreamer(tokenizer=tokenizer, skip_prompt=True)
|
65 |
+
op = model.generate(
|
66 |
+
input_ids,
|
67 |
+
streamer=streamer,
|
68 |
+
pad_token_id=tokenizer.eos_token_id,
|
69 |
+
do_sample=True,
|
70 |
+
temperature=0.7,
|
71 |
+
top_p=0.8,
|
72 |
+
max_new_tokens=512,
|
73 |
+
stopping_criteria=MyStoppingCriteria("</s>", prompt)
|
74 |
+
)
|
75 |
```
|
76 |
|
77 |
+
## Output:
|
78 |
+
>I do not have personal experiences or emotions, but I can provide you with an example of a logical fallacy and its consequences:
|
79 |
+
>
|
80 |
+
>One common logical fallacy is the appeal to authority fallacy. This occurs when someone argues that a particular opinion or belief is true because of who holds it (i.e., "because the doctor said so"). However, this approach does not take into account other factors that may influence the validity of the claim. For instance, if a doctor says that eating a certain food will cure cancer, it does not necessarily mean that it will work for everyone. Other factors such as genetics, lifestyle, and environmental factors could also play a role in whether or not a person gets cancer.
|
81 |
+
>
|
82 |
+
>The consequence of using the appeal to authority fallacy is that it often leads to hasty conclusions and misinformation. It can be difficult to separate fact from fiction, especially when people rely on authority figures to make decisions. As a result, individuals may end up making poor choices based on incomplete information. This can lead to unintended consequences, such as harming oneself or others.
|
83 |
+
>
|
84 |
+
>To avoid falling prey to the appeal to authority fallacy, it is important to seek out multiple sources of information and consider all available evidence before making a decision. This can help individuals make more informed choices and reduce the likelihood of being swayed by unsubstantiated claims.</s>
|