Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -30,29 +30,42 @@ This is the OpenLLM small model trained for 10,000 steps on the SQUAD dataset.
|
|
| 30 |
|
| 31 |
### Using the Model
|
| 32 |
|
|
|
|
|
|
|
| 33 |
```python
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
import torch
|
| 36 |
|
| 37 |
-
# Load
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Generate text
|
| 43 |
prompt = "The future of artificial intelligence"
|
| 44 |
-
|
|
|
|
| 45 |
|
| 46 |
with torch.no_grad():
|
| 47 |
outputs = model.generate(
|
| 48 |
-
inputs
|
| 49 |
max_length=100,
|
| 50 |
-
temperature=0.7
|
| 51 |
-
do_sample=True,
|
| 52 |
-
pad_token_id=tokenizer.eos_token_id
|
| 53 |
)
|
| 54 |
|
| 55 |
-
generated_text = tokenizer.decode(outputs[0]
|
| 56 |
print(generated_text)
|
| 57 |
```
|
| 58 |
|
|
@@ -66,16 +79,17 @@ model, tokenizer = load_model_and_tokenizer("lemms/openllm-small-extended-10k")
|
|
| 66 |
|
| 67 |
# Generate text
|
| 68 |
prompt = "The history of machine learning"
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
with torch.no_grad():
|
| 72 |
outputs = model.generate(
|
| 73 |
-
inputs
|
| 74 |
max_length=100,
|
| 75 |
temperature=0.7
|
| 76 |
)
|
| 77 |
|
| 78 |
-
print(tokenizer.decode(outputs[0]
|
| 79 |
```
|
| 80 |
|
| 81 |
## Model Architecture
|
|
|
|
| 30 |
|
| 31 |
### Using the Model
|
| 32 |
|
| 33 |
+
This model uses a custom configuration format and requires the OpenLLM framework to load properly.
|
| 34 |
+
|
| 35 |
```python
|
| 36 |
+
# Load using the OpenLLM framework
|
| 37 |
+
from core.src.model import GPTModel
|
| 38 |
+
import json
|
| 39 |
import torch
|
| 40 |
|
| 41 |
+
# Load configuration
|
| 42 |
+
with open("config.json", "r") as f:
|
| 43 |
+
config = json.load(f)
|
| 44 |
+
|
| 45 |
+
# Create model instance
|
| 46 |
+
model = GPTModel(config["model_config"])
|
| 47 |
+
|
| 48 |
+
# Load trained weights
|
| 49 |
+
model.load_state_dict(torch.load("pytorch_model.bin", map_location="cpu"))
|
| 50 |
+
|
| 51 |
+
# Load tokenizer
|
| 52 |
+
import sentencepiece as spm
|
| 53 |
+
tokenizer = spm.SentencePieceProcessor()
|
| 54 |
+
tokenizer.load("tokenizer.model")
|
| 55 |
|
| 56 |
# Generate text
|
| 57 |
prompt = "The future of artificial intelligence"
|
| 58 |
+
tokens = tokenizer.encode(prompt)
|
| 59 |
+
inputs = torch.tensor([tokens], dtype=torch.long)
|
| 60 |
|
| 61 |
with torch.no_grad():
|
| 62 |
outputs = model.generate(
|
| 63 |
+
inputs,
|
| 64 |
max_length=100,
|
| 65 |
+
temperature=0.7
|
|
|
|
|
|
|
| 66 |
)
|
| 67 |
|
| 68 |
+
generated_text = tokenizer.decode(outputs[0].tolist())
|
| 69 |
print(generated_text)
|
| 70 |
```
|
| 71 |
|
|
|
|
| 79 |
|
| 80 |
# Generate text
|
| 81 |
prompt = "The history of machine learning"
|
| 82 |
+
tokens = tokenizer.encode(prompt)
|
| 83 |
+
inputs = torch.tensor([tokens], dtype=torch.long)
|
| 84 |
|
| 85 |
with torch.no_grad():
|
| 86 |
outputs = model.generate(
|
| 87 |
+
inputs,
|
| 88 |
max_length=100,
|
| 89 |
temperature=0.7
|
| 90 |
)
|
| 91 |
|
| 92 |
+
print(tokenizer.decode(outputs[0].tolist()))
|
| 93 |
```
|
| 94 |
|
| 95 |
## Model Architecture
|