Upload LSTM model and tokenizer
Browse files- .gitattributes +1 -0
- README.md +80 -0
- config.json +0 -0
- lstm_model/fingerprint.pb +3 -0
- lstm_model/keras_metadata.pb +3 -0
- lstm_model/saved_model.pb +3 -0
- lstm_model/variables/variables.data-00000-of-00001 +3 -0
- lstm_model/variables/variables.index +0 -0
- tokenizer.json +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
lstm_model/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- text-generation
|
| 4 |
+
- lstm
|
| 5 |
+
- tensorflow
|
| 6 |
+
library_name: tensorflow
|
| 7 |
+
pipeline_tag: text-generation
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# LSTM Text Generation Model
|
| 11 |
+
|
| 12 |
+
This model was trained using TensorFlow/Keras for financial article generation tasks.
|
| 13 |
+
|
| 14 |
+
## Model Details
|
| 15 |
+
|
| 16 |
+
- **Model Type**: LSTM
|
| 17 |
+
- **Framework**: TensorFlow/Keras
|
| 18 |
+
- **Task**: Text Generation
|
| 19 |
+
- **Vocabulary Size**: 41376
|
| 20 |
+
- **Architecture**: Long Short-Term Memory (LSTM)
|
| 21 |
+
|
| 22 |
+
## Usage
|
| 23 |
+
|
| 24 |
+
```python
|
| 25 |
+
from huggingface_hub import snapshot_download
|
| 26 |
+
import tensorflow as tf
|
| 27 |
+
import json
|
| 28 |
+
import pickle
|
| 29 |
+
import numpy as np
|
| 30 |
+
|
| 31 |
+
# Download model files
|
| 32 |
+
model_path = snapshot_download(repo_id="firobeid/L4_LSTM_financial_article_generator")
|
| 33 |
+
|
| 34 |
+
# Load the LSTM model
|
| 35 |
+
model = tf.keras.models.load_model(f"{model_path}/lstm_model")
|
| 36 |
+
|
| 37 |
+
# Load tokenizer
|
| 38 |
+
try:
|
| 39 |
+
# Try JSON format first
|
| 40 |
+
with open(f"{model_path}/tokenizer.json", 'r', encoding='utf-8') as f:
|
| 41 |
+
tokenizer_json = f.read()
|
| 42 |
+
tokenizer = tf.keras.preprocessing.text.tokenizer_from_json(tokenizer_json)
|
| 43 |
+
except FileNotFoundError:
|
| 44 |
+
# Fallback to pickle format
|
| 45 |
+
with open(f"{model_path}/tokenizer.pkl", 'rb') as f:
|
| 46 |
+
tokenizer = pickle.load(f)
|
| 47 |
+
|
| 48 |
+
# Text generation function
|
| 49 |
+
def generate_text(input_text, num_words=10):
|
| 50 |
+
# Preprocess input
|
| 51 |
+
X = np.array(tokenizer.texts_to_sequences([input_text])) - 1
|
| 52 |
+
|
| 53 |
+
# Generate predictions
|
| 54 |
+
output_text = []
|
| 55 |
+
for i in range(num_words):
|
| 56 |
+
y_proba = model.predict(X, verbose=0)[0]
|
| 57 |
+
pred_word_ind = np.argmax(y_proba, axis=-1) + 1
|
| 58 |
+
pred_word = tokenizer.index_word[pred_word_ind[-1]]
|
| 59 |
+
|
| 60 |
+
input_text += ' ' + pred_word
|
| 61 |
+
output_text.append(pred_word)
|
| 62 |
+
X = np.array(tokenizer.texts_to_sequences([input_text])) - 1
|
| 63 |
+
|
| 64 |
+
return ' '.join(output_text)
|
| 65 |
+
|
| 66 |
+
# Example usage
|
| 67 |
+
# Start with these tags: <business>, <entertainment>, <politics>, <sport>, <tech>
|
| 68 |
+
result = generate_text("<tech> The future of artificial intelligence", num_words=15)
|
| 69 |
+
print(result)
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
## Training
|
| 73 |
+
|
| 74 |
+
This model was trained on text data using LSTM architecture for next-word prediction.
|
| 75 |
+
|
| 76 |
+
## Limitations
|
| 77 |
+
|
| 78 |
+
- Model performance depends on training data quality and size
|
| 79 |
+
- Generated text may not always be coherent for longer sequences
|
| 80 |
+
- Model architecture is optimized for the specific vocabulary it was trained on
|
config.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
lstm_model/fingerprint.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:76dc228eaab1a254fe2875169b46d865f5a2ec20dcd1d73ed32aaf47dad91207
|
| 3 |
+
size 57
|
lstm_model/keras_metadata.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5608b1773a530424b5af7952ad1b240e0d9fdb4756bc9af171bf950171990f0d
|
| 3 |
+
size 15917
|
lstm_model/saved_model.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ce7b4c755b3d99d8cafb673e9a78b101af96de90fbe20090486a82174b7c7ee6
|
| 3 |
+
size 1475596
|
lstm_model/variables/variables.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:53a39e598a4ee3ee8b93223a92e0b023918a819a51db5087c07029755c4cf8f8
|
| 3 |
+
size 89112282
|
lstm_model/variables/variables.index
ADDED
|
Binary file (705 Bytes). View file
|
|
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|