Update README.md
Browse files
README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
-
|
2 |
---
|
3 |
tags:
|
4 |
- generated_from_triptuner
|
5 |
- transformer
|
6 |
- character-level
|
|
|
7 |
license: mit
|
8 |
library_name: torch
|
9 |
---
|
@@ -15,7 +15,62 @@ It uses a custom transformer-based language model designed to handle character-l
|
|
15 |
|
16 |
## Usage
|
17 |
|
18 |
-
The model
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
## Training Data
|
21 |
|
|
|
|
|
1 |
---
|
2 |
tags:
|
3 |
- generated_from_triptuner
|
4 |
- transformer
|
5 |
- character-level
|
6 |
+
- custom-model
|
7 |
license: mit
|
8 |
library_name: torch
|
9 |
---
|
|
|
15 |
|
16 |
## Usage
|
17 |
|
18 |
+
The Triptuner model cannot be directly used with Hugging Face's built-in Inference API because it uses a custom architecture. Below are the instructions on how to manually load and use this model with PyTorch.
|
19 |
+
|
20 |
+
### Load and Use the Model with PyTorch
|
21 |
+
|
22 |
+
```python
|
23 |
+
import torch
|
24 |
+
|
25 |
+
# Define your custom model class
|
26 |
+
class BigramLanguageModel(nn.Module):
|
27 |
+
# Include the complete definition of your BigramLanguageModel here
|
28 |
+
|
29 |
+
# Example method definitions:
|
30 |
+
def __init__(self):
|
31 |
+
super().__init__()
|
32 |
+
# Define your model layers here as per the training setup
|
33 |
+
# Example:
|
34 |
+
# self.token_embedding_table = nn.Embedding(vocab_size, n_embd)
|
35 |
+
# self.position_embedding_table = nn.Embedding(block_size, n_embd)
|
36 |
+
# self.blocks = nn.Sequential(*[Block(n_embd, n_head=n_head) for _ in range(n_layer)])
|
37 |
+
# self.ln_f = nn.LayerNorm(n_embd)
|
38 |
+
# self.lm_head = nn.Linear(n_embd, vocab_size)
|
39 |
+
|
40 |
+
def forward(self, idx, targets=None):
|
41 |
+
# Define the forward pass as per your model
|
42 |
+
pass
|
43 |
+
|
44 |
+
def generate(self, idx, max_new_tokens):
|
45 |
+
# Implement the generate method for text generation
|
46 |
+
pass
|
47 |
+
|
48 |
+
# Load the model weights from Hugging Face
|
49 |
+
model = BigramLanguageModel()
|
50 |
+
model_url = "https://huggingface.co/yoonusajwardapiit/triptuner/resolve/main/pytorch_model.bin"
|
51 |
+
model_weights = torch.hub.load_state_dict_from_url(model_url, map_location=torch.device('cpu'), weights_only=True)
|
52 |
+
model.load_state_dict(model_weights)
|
53 |
+
model.eval()
|
54 |
+
|
55 |
+
# Define your character mappings
|
56 |
+
chars = sorted(list(set("your_training_text_here"))) # Replace with the actual character set used in training
|
57 |
+
stoi = {ch: i for i, ch in enumerate(chars)}
|
58 |
+
itos = {i: ch for i, ch in enumerate(chars)}
|
59 |
+
encode = lambda s: [stoi[c] for c in s]
|
60 |
+
decode = lambda l: ''.join([itos[i] for i in l])
|
61 |
+
|
62 |
+
# Test the model with a sample prompt
|
63 |
+
prompt = "Hanthana" # Replace with any relevant location or prompt
|
64 |
+
context = torch.tensor([encode(prompt)], dtype=torch.long)
|
65 |
+
|
66 |
+
# Generate text using the model
|
67 |
+
with torch.no_grad():
|
68 |
+
generated = model.generate(context, max_new_tokens=250) # Adjust the number of new tokens as needed
|
69 |
+
|
70 |
+
# Decode and print the generated text
|
71 |
+
generated_text = decode(generated[0].tolist())
|
72 |
+
print(generated_text)
|
73 |
+
|
74 |
|
75 |
## Training Data
|
76 |
|