Views
No views yet
| Item | Value |
|---|---|
| Base architecture | Bidirectional LSTM (2 layers) |
| Task | Multi-class text classification |
| # Classes | 12 |
| Vocab size | 60,000 |
| Max token length | 256 |
| Embedding dim | 128 |
| Test Accuracy | 0.6909 |
| Test F1 (macro) | 0.6191 |
0: business_tech1: crime_weird2: entertainment3: environment4: food_travel5: health6: home_style7: lifestyle8: news_politics9: positive10: science_edu11: sports1import pickle, json, numpy as np
2import tensorflow as tf
3from tensorflow.keras.preprocessing.sequence import pad_sequences
4
5lstm_model = tf.keras.models.load_model('lstm_model.keras')
6with open('keras_tokenizer.pkl', 'rb') as f:
7 tokenizer = pickle.load(f)
8with open('label_meta.json') as f:
9 meta = json.load(f)
10
11ID2LABEL = {int(k): v for k, v in meta['id2label'].items()}
12MAX_LENGTH = meta['max_length']
13
14def predict(text):
15 seq = tokenizer.texts_to_sequences([text])
16 padded = pad_sequences(seq, maxlen=MAX_LENGTH, padding='post', truncating='post')
17 probs = lstm_model.predict(padded, verbose=0).squeeze()
18 idx = int(np.argmax(probs))
19 return {'label': ID2LABEL[idx], 'score': float(probs[idx])}
20
21print(predict('AI is transforming healthcare with new diagnostic tools'))