Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
language:
|
@@ -40,3 +41,82 @@ This model, designed and pretrained from scratch, was developed without utilizin
|
|
40 |
For tokenization, this model uses:
|
41 |
```python
|
42 |
tokenizer = tiktoken.get_encoding("gpt2")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
---
|
3 |
license: apache-2.0
|
4 |
language:
|
|
|
41 |
For tokenization, this model uses:
|
42 |
```python
|
43 |
tokenizer = tiktoken.get_encoding("gpt2")
|
44 |
+
```
|
45 |
+
|
46 |
+
## How to Use the Model
|
47 |
+
|
48 |
+
### Load and Generate Text
|
49 |
+
Below is a Python example on how to load the model and generate text:
|
50 |
+
|
51 |
+
```python
|
52 |
+
import torch
|
53 |
+
from torch.nn import functional as F
|
54 |
+
from gpt_class import GPTConfig, GPT
|
55 |
+
import tiktoken
|
56 |
+
|
57 |
+
# Set up the device
|
58 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
59 |
+
|
60 |
+
# Load the model
|
61 |
+
state_dict = torch.load('model_51999.pt', map_location=device)
|
62 |
+
config = state_dict['config']
|
63 |
+
model = GPT(config)
|
64 |
+
model.load_state_dict(state_dict['model'])
|
65 |
+
model.to(device)
|
66 |
+
model.eval()
|
67 |
+
|
68 |
+
# Seed for reproducibility
|
69 |
+
torch.manual_seed(42)
|
70 |
+
torch.cuda.manual_seed_all(42)
|
71 |
+
|
72 |
+
# Tokenizer
|
73 |
+
tokenizer = tiktoken.get_encoding("gpt2")
|
74 |
+
|
75 |
+
def Generate(model, tokenizer, example, num_return_sequences, max_length):
|
76 |
+
model.eval()
|
77 |
+
tokens = tokenizer.encode(example)
|
78 |
+
tokens = torch.tensor(tokens, dtype=torch.long).unsqueeze(0).repeat(num_return_sequences, 1)
|
79 |
+
tokens = tokens.to(device)
|
80 |
+
sample_rng = torch.Generator(device=device)
|
81 |
+
|
82 |
+
xgen = tokens
|
83 |
+
while xgen.size(1) < max_length:
|
84 |
+
with torch.no_grad():
|
85 |
+
with torch.autocast(device_type=device):
|
86 |
+
logits, _ = model(xgen)
|
87 |
+
logits = logits[:, -1, :]
|
88 |
+
probs = F.softmax(logits, dim=-1)
|
89 |
+
topk_probs, topk_indices = torch.topk(probs, 50, dim=-1)
|
90 |
+
ix = torch.multinomial(topk_probs, 1, generator=sample_rng)
|
91 |
+
xcol = torch.gather(topk_indices, -1, ix)
|
92 |
+
xgen = torch.cat((xgen, xcol), dim=1)
|
93 |
+
|
94 |
+
for i in range(num_return_sequences):
|
95 |
+
tokens = xgen[i, :max_length].tolist()
|
96 |
+
decoded = tokenizer.decode(tokens)
|
97 |
+
print(f"Sample {i+1}: {decoded}")
|
98 |
+
|
99 |
+
# Example usage
|
100 |
+
Generate(model, tokenizer, example="As we entered the forest we saw", num_return_sequences=4, max_length=32)
|
101 |
+
```
|
102 |
+
|
103 |
+
### Sample Output
|
104 |
+
```
|
105 |
+
Sample 1: As we entered the forest we saw huge white pine fells at the tops of the high plateaus (the great peaks) and trees standing at ground level.
|
106 |
+
Sample 2: As we entered the forest we saw a few trees that were too large. We realized they were not going to be very big. There was one tree that was
|
107 |
+
Sample 3: As we entered the forest we saw a group of small, wood-dwelling bees who had managed to escape a predator. A farmer was holding a handful
|
108 |
+
Sample 4: As we entered the forest we saw giant, blue-eyed, spotted beetles on the ground, a grayling beetle in my lawn next to the pond, an
|
109 |
+
```
|
110 |
+
|
111 |
+
## Contributions
|
112 |
+
Contributions, feedback, and discussions are welcome. Please feel free to contribute or suggest improvements through the project's repository.
|
113 |
+
```
|
114 |
+
|
115 |
+
### Explanation
|
116 |
+
- **License and Language**: Specifies the open-source Apache 2.0 license and the bilingual capabilities (Hindi and English).
|
117 |
+
- **Model Description**: Elaborates on the independent development and training of the model.
|
118 |
+
- **Model Parameters**: Lists detailed specifications for the model configuration.
|
119 |
+
- **How to Use the Model**: Provides complete code to load the model, set up the environment, and generate text.
|
120 |
+
- **Sample Output**: Demonstrates example outputs to show what the model is capable of generating.
|
121 |
+
|
122 |
+
This model card is ready to be used for your Hugging Face Model Hub submission, ensuring users have a comprehensive understanding of the model's capabilities and setup.
|