Aananda-giri
commited on
Commit
•
9252393
1
Parent(s):
eeaf923
Update README.md
Browse files
README.md
CHANGED
@@ -7,4 +7,77 @@ tags:
|
|
7 |
|
8 |
This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
|
9 |
- Library: https://huggingface.co/Aananda-giri/GPT2-Nepali/
|
10 |
-
- Docs: [More Information Needed]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
|
9 |
- Library: https://huggingface.co/Aananda-giri/GPT2-Nepali/
|
10 |
+
- Docs: [More Information Needed]
|
11 |
+
|
12 |
+
---
|
13 |
+
|
14 |
+
# GPT-2-Nepali-512 Model
|
15 |
+
* 512 represents context length
|
16 |
+
|
17 |
+
* This repository contains a custom GPT-2 model trained on Nepali text. Follow the instructions below to use this model for text generation.
|
18 |
+
|
19 |
+
---
|
20 |
+
|
21 |
+
## How to Use the Model
|
22 |
+
|
23 |
+
1. **Download the Required Code**
|
24 |
+
Save the [`model_code.py`](https://github.com/Aananda-giri/llm.np/blob/main/3.%20GPT-2/sebastian_gutenberg/huggingface_hub/model_code.py) file in the same directory where you'll run the script.
|
25 |
+
|
26 |
+
2. **Install Required Libraries**
|
27 |
+
Ensure you have the necessary libraries installed:
|
28 |
+
```bash
|
29 |
+
pip install transformers torch
|
30 |
+
```
|
31 |
+
|
32 |
+
3. **Run the Following Code**
|
33 |
+
Here's an example to load the model and generate text:
|
34 |
+
|
35 |
+
```python
|
36 |
+
import torch
|
37 |
+
from model_code import GPTModel, generate_and_print_sample
|
38 |
+
from transformers import PreTrainedTokenizerFast
|
39 |
+
|
40 |
+
# Load the tokenizer
|
41 |
+
tokenizer = PreTrainedTokenizerFast.from_pretrained("Aananda-giri/NepaliBPE")
|
42 |
+
|
43 |
+
# Define the starting text
|
44 |
+
start_context = "रामले भात"
|
45 |
+
|
46 |
+
# Load the pre-trained model
|
47 |
+
loaded_model = GPTModel.from_pretrained("Aananda-giri/GPT2-Nepali")
|
48 |
+
|
49 |
+
# Move the model to the appropriate device (CPU or GPU)
|
50 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
51 |
+
loaded_model.to(device)
|
52 |
+
|
53 |
+
# Generate text
|
54 |
+
generate_and_print_sample(
|
55 |
+
loaded_model, tokenizer, device, start_context
|
56 |
+
)
|
57 |
+
```
|
58 |
+
|
59 |
+
---
|
60 |
+
|
61 |
+
## Additional Notes
|
62 |
+
|
63 |
+
- **Tokenizer**: The model uses a pre-trained tokenizer available at `Aananda-giri/NepaliBPE`. Ensure this is downloaded and accessible during runtime.
|
64 |
+
- **Dependencies**: This code requires `transformers` (by Hugging Face) and `torch` (PyTorch). Install them if not already installed.
|
65 |
+
- **Device Compatibility**: The script automatically detects if a CUDA-enabled GPU is available and utilizes it for faster inference. If not, it defaults to the CPU.
|
66 |
+
|
67 |
+
---
|
68 |
+
|
69 |
+
## Example Output
|
70 |
+
|
71 |
+
Input:
|
72 |
+
```
|
73 |
+
रामले भात
|
74 |
+
```
|
75 |
+
|
76 |
+
Generated Text:
|
77 |
+
```
|
78 |
+
रामले भात खाएर सन्तोष माने। ऊ आफ्ना साथीहरूसँग रमाइलो गरिरहेको थियो।
|
79 |
+
```
|
80 |
+
|
81 |
+
---
|
82 |
+
|
83 |
+
Let me know if you'd like further assistance!
|