LaciaStudio commited on
Commit
a4ef65a
·
verified ·
1 Parent(s): e1acf14

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -7
README.md CHANGED
@@ -144,13 +144,34 @@ Users (both direct and downstream) should be aware of the following recommendati
144
  Use the code below to get started with the model:
145
 
146
  ```python
147
- from transformers import pipeline
148
-
149
- classifier = pipeline("text-classification", model="LaciaStudio/Luna_v1")
150
-
151
- text = "text-example"
152
- result = classifier(text)
153
- print(result)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  ```
155
 
156
  ## Training Details
 
144
  Use the code below to get started with the model:
145
 
146
  ```python
147
+ import pickle
148
+ import re
149
+ import numpy as np
150
+ import tensorflow as tf
151
+
152
+ model = tf.keras.models.load_model("path/to/model.h5")
153
+ with open("path/to/vectorizer.pkl", "rb") as vec_file:
154
+ vectorizer = pickle.load(vec_file)
155
+
156
+ def clean_text(text):
157
+ return re.sub(r"[^\w\s]", "", text).lower()
158
+
159
+ def classify_text(text, threshold=0.5):
160
+ text = clean_text(text)
161
+ words = text.split()
162
+ X = vectorizer.transform(words).toarray()
163
+ predictions = model.predict(X)
164
+ result = {}
165
+ for word, pred in zip(words, predictions):
166
+ result[word] = {"probability": round(float(pred), 3), "classification": "Dirty word" if pred >= threshold else "Normal"}
167
+ return result
168
+
169
+ if __name__ == "__main__":
170
+ text = "text example here"
171
+ result = classify_text(text)
172
+ print("Classification result:")
173
+ for word, data in result.items():
174
+ print(f"{word}: {data['probability']} ({data['classification']})")
175
  ```
176
 
177
  ## Training Details