Instructions to use MrVJavlon4002/Comment-Classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MrVJavlon4002/Comment-Classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="MrVJavlon4002/Comment-Classifier")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("MrVJavlon4002/Comment-Classifier", device_map="auto") - Notebooks
- Google Colab
- Kaggle
| import gradio as gr | |
| import joblib | |
| from gensim.models import Word2Vec | |
| import numpy as np | |
| # Load the models | |
| classifier = joblib.load("random_forest_model.pkl") | |
| word2vec_model = Word2Vec.load("word2vec_model.bin") | |
| label_encoder = joblib.load("label_encoder.pkl") | |
| def predict_comment(comment): | |
| tokenized_comment = comment.split() | |
| comment_vector = get_average_word2vec(tokenized_comment, word2vec_model, 100) | |
| comment_vector = comment_vector.reshape(1, -1) | |
| prediction = classifier.predict(comment_vector) | |
| return "Based on Experience" if label_encoder.inverse_transform(prediction)[0] == 1 else "Not Based on Experience" | |
| def get_average_word2vec(comment, model, num_features): | |
| feature_vec = np.zeros((num_features,), dtype="float32") | |
| n_words = 0 | |
| for word in comment: | |
| if word in model.wv.key_to_index: | |
| n_words += 1 | |
| feature_vec = np.add(feature_vec, model.wv[word]) | |
| if n_words > 0: | |
| feature_vec = np.divide(feature_vec, n_words) | |
| return feature_vec | |
| # Gradio interface | |
| iface = gr.Interface(fn=predict_comment, inputs="text", outputs="text") | |
| iface.launch() | |