Run this model with HF Jobs
Run NightPrince/Toxic_Classification on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/NightPrince/Toxic_Classification. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/NightPrince/Toxic_Classification on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use NightPrince/Toxic_Classification with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use NightPrince/Toxic_Classification with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0. # See https://github.com/keras-team/tf-keras for more details. # !pip install "huggingface_hub<1.0" tf_keras from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("NightPrince/Toxic_Classification") - Keras
How to use NightPrince/Toxic_Classification with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://NightPrince/Toxic_Classification") - Notebooks
- Google Colab
- Kaggle
Update pipeline.py
Browse files2 unmodified lines34567895 unmodified lines1516171819202122236 unmodified lines3031323334352 unmodified linesfrom tensorflow.keras.preprocessing.sequence import pad_sequencesfrom tensorflow.keras.preprocessing.text import tokenizer_from_jsonimport jsonclass Pipeline:def __init__(self):# Load tokenizer5 unmodified lines# Load model (SavedModel format)self.model = tf.keras.models.load_model(".")# Optional: load label mapself.label_map = Noneif tf.io.gfile.exists("label_map.json"):with open("label_map.json", "r", encoding="utf-8") as f:self.label_map = json.load(f)6 unmodified linespadded = pad_sequences(seq, maxlen=self.max_len, padding='post', truncating='post')pred_probs = self.model.predict(padded)pred_label = int(np.argmax(pred_probs, axis=1)[0])if self.label_map:return {"label": self.label_map.get(str(pred_label), pred_label), "score": float(np.max(pred_probs))}return {"label": pred_label, "score": float(np.max(pred_probs))}2 unmodified lines345678910115 unmodified lines1718192021222324256 unmodified lines3233343536373839402 unmodified linesfrom tensorflow.keras.preprocessing.sequence import pad_sequencesfrom tensorflow.keras.preprocessing.text import tokenizer_from_jsonimport jsonimport os# Hugging Face expects a class named Pipeline with __call__(self, inputs)class Pipeline:def __init__(self):# Load tokenizer5 unmodified lines# Load model (SavedModel format)self.model = tf.keras.models.load_model(".")# Load label map if availableself.label_map = Noneif os.path.exists("label_map.json"):with open("label_map.json", "r", encoding="utf-8") as f:self.label_map = json.load(f)6 unmodified linespadded = pad_sequences(seq, maxlen=self.max_len, padding='post', truncating='post')pred_probs = self.model.predict(padded)pred_label = int(np.argmax(pred_probs, axis=1)[0])score = float(np.max(pred_probs))if self.label_map:label = self.label_map.get(str(pred_label), pred_label)else:label = pred_labelreturn {"label": label, "score": score}
pipeline.py+9-4