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 sentence_transformers import SentenceTransformer # pip install -U sentence-transformers | |
from sklearn.cluster import KMeans | |
from collections import defaultdict | |
INPUT_FILE = "/tmp/test_input.txt" | |
with open(INPUT_FILE, "r") as f: | |
lines = f.read().splitlines() | |
print(len(lines)) |
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 | |
import numpy as np | |
from tqdm import tqdm | |
from fairseq.models.roberta import RobertaModel | |
from fairseq.data.data_utils import collate_tokens | |
from torch.utils.data import DataLoader, SequentialSampler | |
roberta = torch.hub.load('pytorch/fairseq', 'roberta.large.mnli') | |
roberta.eval() | |
roberta.cuda() |
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
``` | |
wget https://s3.amazonaws.com/conceptnet/downloads/2017/edges/conceptnet-assertions-5.5.5.csv.gz | |
gunzip -k conceptnet-assertions-5.5.5.csv.gz | |
``` | |
import json | |
def del_pos(s): | |
""" | |
Deletes part-of-speech encoding from an entity string, if present. |
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 OpenAIGPTTokenizer, OpenAIGPTLMHeadModel | |
from transformers import GPT2Tokenizer, GPT2LMHeadModel | |
import numpy as np | |
from scipy.special import softmax | |
def model_init(model_string, cuda): | |
if model_string.startswith("gpt2"): | |
tokenizer = GPT2Tokenizer.from_pretrained(model_string) | |
model = GPT2LMHeadModel.from_pretrained(model_string) |
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 BertTokenizer, BertModel, BertForMaskedLM | |
import logging | |
logging.basicConfig(level=logging.INFO)# OPTIONAL | |
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') | |
model = BertForMaskedLM.from_pretrained('bert-base-uncased') | |
model.eval() |
NewerOlder