Views
No views yet
1from transformers import AutoTokenizer, AutoModelForCausalLM, StoppingCriteria, StoppingCriteriaList
2
3class CustomStoppingCriteria(StoppingCriteria):
4 def __init__(self, stop_token, tokenizer):
5 self.stop_token = stop_token
6 self.tokenizer = tokenizer
7
8 def __call__(self, input_ids, scores, **kwargs):
9 decoded_output = self.tokenizer.decode(input_ids[0], skip_special_tokens=True)
10 if self.stop_token in decoded_output:
11 return True
12 return False
13
14stop_token = "END." # The model was trained with this special end of text token.
15stopping_criteria = StoppingCriteriaList([CustomStoppingCriteria(stop_token, tokenizer)])
16
17tokenizer = AutoTokenizer.from_pretrained("gustavecortal/oneirogen-7B")
18model = AutoModelForCausalLM.from_pretrained("gustavecortal/oneirogen-7B", torch_dtype=torch.float16)
19model.to("cuda")
20
21text = "Dream:" # The model was trained with this prefix
22
23inputs = tokenizer(text, return_tensors="pt").to("cuda")
24outputs = model.generate(inputs["input_ids"], attention_mask=inputs["attention_mask"], max_new_tokens=256, top_k = 50, top_p = 0.95, do_sample = True, temperature=0.9, num_beams = 1, repetition_penalty= 1.11, stopping_criteria=stopping_criteria)
25print(tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=False)[0])Our environment – and I mean our man-made world of machines, artificial constructs, computers, electronic systems, interlinking homeostatic components – all of this is in fact beginning more and more to possess what the earnest psychologists fear the primitive sees in his environment: animation. In a very real sense our environment is becoming alive, or at least quasi-alive, and in ways specifically and fundamentally analogous to ourselves... Rather than learning about ourselves by studying our constructs, perhaps we should make the attempt to comprehend what our constructs are up to by looking into what we ourselves are up to