Skip to content

Instantly share code, notes, and snippets.

@EricFillion
EricFillion / styleformer-with-happy-transformer
Created August 1, 2021 21:30
Styleformer With Happy Transformer
# In terminal
# pip install happytransformer
# Python code below
#------------------------------------------------------------------------------------------------------------------------------
# Casual to Formal
#------------------------------------------------------------------------------------------------------------------------------
from happytransformer import HappyTextToText
@EricFillion
EricFillion / gist:e0205f9cb9f501191384cf917a9df0f3
Last active March 17, 2023 07:00
GPT-Neo For Answering Questions
# pip install happytransformer
from happytransformer import HappyGeneration
happy_gen = HappyGeneration("GPT-NEO", "EleutherAI/gpt-neo-125M")
result = happy_gen.generate_text("What is natural language processing?")
print(result.text)
# ----------------------------
# Result:
@EricFillion
EricFillion / zero-shot-text-classification
Last active May 5, 2021 06:32
Zero Shot Text Classification
# pip install transformers
from transformers import pipeline
tags = ["travel", "surfing", "Indonesia", "Bali", "cryptocurrencies", "bitcoin", "mining", "gardening", "plants"]
sequences = ["Best surf camp in Bali", "How do I build a crypto mining rig?", "my plant has yellow leaves"]
classifer = pipeline("zero-shot-classification")
for text in sequences:
@EricFillion
EricFillion / classify-gender
Created May 5, 2021 03:49
NLP: Gender Detection
# pip install gender-guesser
from gender_guesser.detector import Detector
gender_detector = Detector()
names = ["Eric", "Kylie", "Spencer", "Erin"]
for name in names:
result = gender_detector.get_gender(name)
print(name + ":", result)
@EricFillion
EricFillion / fine-tuning-hate-speech
Created February 6, 2021 18:19
Fine-tuning a Hate Speech Detection Model
from happytransformer import HappyTextClassification
from datasets import load_dataset
import csv
# Colab: https://colab.research.google.com/drive/1z8m5QYi2tcQLd3m_fESK37SYbMBSqTO7?usp=sharing
def run_finetune():
train_csv_path = "train.csv"
eval_csv_path = "eval.csv"
from datasets import load_dataset
import csv
from happytransformer.happy_question_answering import HappyQuestionAnswering
def main():
# Be careful not to commit the csv files to the rep
train_csv_path = "train.csv"
eval_csv_path = "eval.csv"