Airin-chan commited on
Commit
548f078
·
verified ·
1 Parent(s): 2b53104

Upload 2 files

Browse files
Files changed (2) hide show
  1. lctlm1.py +34 -0
  2. lctlm1_finetuned.pth +3 -0
lctlm1.py CHANGED
@@ -1,6 +1,8 @@
1
  import torch
2
  from torch import nn
3
  from typing import Optional
 
 
4
  class LCMBlock (nn.Module) :
5
  """
6
  LCm (Laten Connected Model ) block, looking attention as two preception and icreasing it
@@ -84,3 +86,35 @@ class LMLCT1(nn.Module):
84
  x = self.decoder_mlp(x)
85
  logits = self.out(x)
86
  return logits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import torch
2
  from torch import nn
3
  from typing import Optional
4
+ import torch.nn.functional as F
5
+ from tokenizers import Tokenizer
6
  class LCMBlock (nn.Module) :
7
  """
8
  LCm (Laten Connected Model ) block, looking attention as two preception and icreasing it
 
86
  x = self.decoder_mlp(x)
87
  logits = self.out(x)
88
  return logits
89
+
90
+
91
+ def generate_tesk(model: LMLCT1, texts: str, tokenizer: Tokenizer, temperature: float = 1.0):
92
+ texts = "sos " + texts
93
+ input_ids = tokenizer.encode(texts).ids
94
+ start_index = len(input_ids)
95
+
96
+ input_ids = torch.tensor(input_ids, dtype=torch.long).unsqueeze(0)
97
+ zeros_tolerant = 0
98
+ response_tokens = []
99
+
100
+ for _ in range(start_index,500):
101
+
102
+ if zeros_tolerant >= 3 :
103
+ break
104
+ with torch.no_grad():
105
+ logits = model(input_ids)
106
+ logits = logits[:, -1, :]
107
+
108
+ logits = logits / temperature
109
+
110
+ probs = F.softmax(logits, dim=-1)
111
+ next_token = torch.multinomial(probs, num_samples=1)
112
+
113
+ if next_token == 0 :
114
+ zeros_tolerant +=1
115
+ next_token_id = next_token.item()
116
+
117
+ response_tokens.append(next_token_id)
118
+ input_ids = torch.cat([input_ids, next_token], dim=1)
119
+
120
+ return tokenizer.decode(response_tokens).strip()
lctlm1_finetuned.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9af67ced6736aa23454b15d6025f2dd692ba43b8de267001419bee55386c71f3
3
+ size 176885767