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 utils.data.paths import resources_path | |
from torch.utils.data import random_split | |
from transformers.optimization import AdamW | |
from ignite.engine import Engine, Events | |
from ignite.metrics import RunningAverage, Accuracy, Precision | |
from ignite.handlers import ModelCheckpoint, EarlyStopping | |
from torch.utils.data import DataLoader | |
from ignite.contrib.handlers import ProgressBar | |
from transformers import BertForSequenceClassification, AutoTokenizer |
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 torch import nn | |
import os | |
from transformers import BertForSequenceClassification, AutoTokenizer | |
def extract_sentiment(model, tokenizer, text, device): | |
# Encode the text, create a tensor and move to device. | |
tensor = torch.tensor(tokenizer.encode(text, add_special_tokens=True)).unsqueeze(0).long().to(device) |
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 torch.utils.data import Dataset | |
import json | |
class TweetDataset(Dataset): | |
def __init__(self, path, device): | |
self.device = device | |
# Load the JSON file containing our pre-processed data |
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 multiprocessing import cpu_count | |
import pandas as pd | |
import numpy as np | |
from multiprocessing import Pool | |
from transformers import AutoTokenizer | |
import spacy | |
class TweetProcessor: |