This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from transformers import pipeline | |
classifier = pipeline("text-classification", model="hadifar/xxx") | |
try: | |
while True: | |
user_input = input("Enter a string (Press Ctrl+C to stop): ") | |
if user_input: | |
res = classifier([user_input]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_name = 'model/classifier' | |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model.push_to_hub('hadifar/xxx') | |
tokenizer.push_to_hub('hadifar/xxx') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import evaluate | |
import numpy as np | |
import random | |
import torch | |
from datasets import load_dataset | |
from transformers import AutoTokenizer | |
from transformers import DataCollatorWithPadding | |
from transformers import AutoModelForSequenceClassification, TrainingArguments, Trainer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import os | |
import numpy as np | |
from joblib import dump, load | |
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.metrics import accuracy_score | |
from sklearn.pipeline import Pipeline | |
from sklearn.svm import SVC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import nltk | |
def get_verb_phrases(t): | |
verb_phrases = [] | |
num_children = len(t) | |
num_VP = sum(1 if t[i].label() == "VP" else 0 for i in range(0, num_children)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from transformers import * | |
import sys, logging | |
print('cuda available? ', torch.cuda.is_available()) | |
print('how many gpus?', torch.cuda.device_count()) | |
logging.root.handlers = [] | |
logging.basicConfig(level="INFO", format='%(asctime)s:%(levelname)s: %(message)s', stream=sys.stdout) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
vocabulary_size = 10000 | |
embedding_size = 64 | |
rnn_size = 64 | |
batch_size = 512 | |
# download dataset | |
(train_data, train_labels), (test_data, test_labels) = tf.keras.datasets.imdb.load_data(num_words=vocabulary_size) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NUM_GPUS = 4 | |
strategy = tf.contrib.distribute.MirroredStrategy(num_gpus=NUM_GPUS) | |
config = tf.estimator.RunConfig(train_distribute=strategy) | |
estimator = tf.estimator.Estimator(model, config=config) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Instantiate a Keras inception v3 model. | |
keras_inception_v3 = tf.keras.applications.inception_v3.InceptionV3(weights=None) | |
keras_inception_v3.compile(optimizer=tf.keras.optimizers.SGD(lr=0.0001, momentum=0.9), | |
loss='categorical_crossentropy', | |
metric='accuracy') | |
est_inception_v3 = tf.keras.estimator.model_to_estimator(keras_model=keras_inception_v3) | |
train_input_fn = tf.estimator.inputs.numpy_input_fn( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model_estimator = tf.estimator.Estimator(model_fn=model_fn, model_dir='./tmp/') | |
model_estimator.train(train_input_fn, max_steps=5000) | |
result = model_estimator.evaluate(test_input_fn) | |
print(result) |
NewerOlder