Wiped her memory
This commit is contained in:
parent
12df801a44
commit
a23a2fa7d7
@ -14,7 +14,7 @@ recent_dreams = []
|
|||||||
def generate_response():
|
def generate_response():
|
||||||
model.eval()
|
model.eval()
|
||||||
|
|
||||||
# Start from an empty tensor: she speaks purely from herself
|
# Start from an empty input: purely organic thought
|
||||||
input_ids = torch.zeros((1, 1), dtype=torch.long, device=DEVICE)
|
input_ids = torch.zeros((1, 1), dtype=torch.long, device=DEVICE)
|
||||||
|
|
||||||
output_tokens = []
|
output_tokens = []
|
||||||
@ -25,8 +25,14 @@ def generate_response():
|
|||||||
next_token_logits = output[:, -1, :]
|
next_token_logits = output[:, -1, :]
|
||||||
next_token = torch.argmax(next_token_logits, dim=-1)
|
next_token = torch.argmax(next_token_logits, dim=-1)
|
||||||
|
|
||||||
# Stop if the model predicts padding or unknown token
|
# Get token id values for special tokens
|
||||||
if next_token.item() in [tokenizer.token_to_id("<pad>"), tokenizer.token_to_id("<unk>")]:
|
pad_token_id = tokenizer.vocab.get("<pad>", None)
|
||||||
|
unk_token_id = tokenizer.vocab.get("<unk>", None)
|
||||||
|
|
||||||
|
# Stop if the model predicts <pad> or <unk>
|
||||||
|
if pad_token_id is not None and next_token.item() == pad_token_id:
|
||||||
|
break
|
||||||
|
if unk_token_id is not None and next_token.item() == unk_token_id:
|
||||||
break
|
break
|
||||||
|
|
||||||
output_tokens.append(next_token.item())
|
output_tokens.append(next_token.item())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user