shiv-am-04
commited on
Upload folder using huggingface_hub
Browse files- config.json +18 -0
- en_tokenizer.json +0 -0
- fr_tokenizer.json +0 -0
- model_weight/model.weights.h5 +3 -0
- translate.py +32 -0
config.json
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"model_type": "custom-translation",
|
3 |
+
"architecture": "Keras Sequential",
|
4 |
+
"language": "en",
|
5 |
+
"task": "translation",
|
6 |
+
"max_seq_length": 50,
|
7 |
+
"tokenizer": {
|
8 |
+
"type": "custom",
|
9 |
+
"file_1": "en_tokenizer.json",
|
10 |
+
"file_2": "fr_tokenizer.json"
|
11 |
+
},
|
12 |
+
"framework": "tensorflow",
|
13 |
+
"description": "This is a custom translation model built using TensorFlow Keras and integrated with a tokenizer for seamless text translation. It supports tokenization and text generation directly using a user-defined function.",
|
14 |
+
"custom_class_file": "translation_model.py",
|
15 |
+
"version": 1.0,
|
16 |
+
"author": "Shivam Ghuge",
|
17 |
+
"license": "apache-2.0"
|
18 |
+
}
|
en_tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
fr_tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model_weight/model.weights.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:82bf670e412232ab115881757ade0d35b95721444529dc042744c0ec63808062
|
3 |
+
size 552959904
|
translate.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from tensorflow.keras.preprocessing.text import tokenizer_from_json
|
3 |
+
from tensorflow.keras.preprocessing.sequence import pad_sequences
|
4 |
+
from tensorflow.keras.models import load_model
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
class TranslationModel:
|
8 |
+
def __init__(self, model_path,en_tokenizer,fr_tokenizer,max_len):
|
9 |
+
# Load the Keras model
|
10 |
+
self.model = load_model(model_path)
|
11 |
+
|
12 |
+
self.english_tokenizer = en_tokenizer
|
13 |
+
|
14 |
+
self.french_tokenizer = fr_tokenizer
|
15 |
+
|
16 |
+
# Define max sequence length
|
17 |
+
self.max_seq_length = max_len
|
18 |
+
|
19 |
+
def logits_index(self,text):
|
20 |
+
input_sequence = self.english_tokenizer.texts_to_sequences([text])
|
21 |
+
padded_input_sequence = pad_sequences(input_sequence, maxlen=self.max_seq_length, padding='post')
|
22 |
+
decoded_text = '<start>'
|
23 |
+
|
24 |
+
for i in range(self.max_seq_length):
|
25 |
+
target_sequence = self.french_tokenizer.texts_to_sequences([decoded_text])
|
26 |
+
padded_target_sequence = pad_sequences(target_sequence, maxlen=self.max_seq_length, padding='post')[:, :-1]
|
27 |
+
|
28 |
+
prediction = self.model([padded_input_sequence, padded_target_sequence])
|
29 |
+
|
30 |
+
idx = np.argmax(prediction[0, i, :])
|
31 |
+
|
32 |
+
return idx
|