-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilz.py
32 lines (25 loc) · 1.01 KB
/
utilz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from config import Config
from pprint import pprint, pformat
import logging
from pprint import pprint, pformat
logging.basicConfig(format="%(levelname)-8s:%(filename)s.%(funcName)20s >> %(message)s")
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
import torch
from torch import nn
from torch.autograd import Variable
from collections import namedtuple, defaultdict
"""
from nltk.tokenize import WordPunctTokenizer
word_punct_tokenizer = WordPunctTokenizer()
word_tokenize = word_punct_tokenizer.tokenize
"""
from anikattu.tokenizer import word_tokenize
VOCAB = ['PAD', 'UNK', 'GO', 'EOS']
PAD = VOCAB.index('PAD')
"""
Local Utilities, Helper Functions
"""
BoundarySample = namedtuple('BoundarySample', ['id', 'aid', 'pid', 'qid', 'squad_id', 'story', 'q', 'a', 'a_start', 'a_end'])
SequenceSample = namedtuple('SequenceSample', ['id', 'aid', 'pid', 'qid', 'squad_id', 'story', 'q', 'a', 'a_positions'])
PtrGenSample = namedtuple('PtrGenSample', ['id', 'aid', 'pid', 'qid', 'squad_id', 'story', 'q', 'a'])