group singular and plural forms in clouds
Browse filesFiles changed (2)
- handler.py+15-17
- utils.py+5-1
9 unmodified lines10111213141516165 unmodified lines18218318418518618718818919019119219319419519619719819920020163 unmodified lines26526626726826927027127 unmodified lines2993003013023033043059 unmodified linesfrom utils import clean_str, clean_str_nopunctimport torchfrom utils import MultiHeadModel, BertInputBuilder, get_num_words, MATH_PREFIXES, MATH_WORDSimport transformersfrom transformers import BertTokenizer, BertForSequenceClassification165 unmodified linesteacher_dict.update(general_words)else:student_dict.update(general_words)dict_list = []uptake_dict_list = []teacher_dict_list = []student_dict_list = []for word in uptake_teacher_dict.keys():uptake_dict_list.append({'text': word, 'value': uptake_teacher_dict[word], 'category': 'teacher'})for word in teacher_dict.keys():teacher_dict_list.append({'text': word, 'value': teacher_dict[word], 'category': 'general'})dict_list.append({'text': word, 'value': teacher_dict[word], 'category': 'general'})for word in student_dict.keys():student_dict_list.append({'text': word, 'value': student_dict[word], 'category': 'general'})dict_list.append({'text': word, 'value': student_dict[word], 'category': 'general'})sorted_dict_list = sorted(dict_list, key=lambda x: x['value'], reverse=True)sorted_uptake_dict_list = sorted(uptake_dict_list, key=lambda x: x['value'], reverse=True)sorted_teacher_dict_list = sorted(teacher_dict_list, key=lambda x: x['value'], reverse=True)63 unmodified linesreturn_pooler_output=False)return outputclass ReasoningModel:def __init__(self, device, tokenizer, input_builder, max_length=128, path=REASONING_MODEL):print("Loading models...")27 unmodified linestoken_type_ids=instance["token_type_ids"])return outputclass UptakeModel:def __init__(self, device, tokenizer, input_builder, max_length=120, path=UPTAKE_MODEL):print("Loading models...")9 unmodified lines10111213141516165 unmodified lines18218318418518618718818919019119219319419519619719819920020163 unmodified lines26526626726826927027 unmodified lines2982993003013023039 unmodified linesfrom utils import clean_str, clean_str_nopunctimport torchfrom utils import MultiHeadModel, BertInputBuilder, get_num_words, MATH_PREFIXES, MATH_WORDS, plural_to_singularimport transformersfrom transformers import BertTokenizer, BertForSequenceClassification165 unmodified linesteacher_dict.update(general_words)else:student_dict.update(general_words)def dict_to_list(d, category):combined_dict = Counter()for word, count in d.items():singular_word = plural_to_singular(word)combined_dict[singular_word] += countreturn [{'text': word, 'value': count, 'category': category} for word, count in combined_dict.items()]# Sorting and trimming dictionariesdict_list = dict_to_list(teacher_dict, 'general') + dict_to_list(student_dict, 'general')uptake_dict_list = dict_to_list(uptake_teacher_dict, 'teacher')teacher_dict_list = dict_to_list(teacher_dict, 'general')student_dict_list = dict_to_list(student_dict, 'general')sorted_dict_list = sorted(dict_list, key=lambda x: x['value'], reverse=True)sorted_uptake_dict_list = sorted(uptake_dict_list, key=lambda x: x['value'], reverse=True)sorted_teacher_dict_list = sorted(teacher_dict_list, key=lambda x: x['value'], reverse=True)63 unmodified linesreturn_pooler_output=False)return outputclass ReasoningModel:def __init__(self, device, tokenizer, input_builder, max_length=128, path=REASONING_MODEL):print("Loading models...")27 unmodified linestoken_type_ids=instance["token_type_ids"])return outputclass UptakeModel:def __init__(self, device, tokenizer, input_builder, max_length=120, path=UPTAKE_MODEL):print("Loading models...")
810 unmodified lines811812813814815816817810 unmodified linesdef singular_to_plural(word):"""Convert singular words to plural using inflect."""plural = p.plural(word)return plural if plural else wordplural_MATH_WORDS = [singular_to_plural(word) for word in MATH_WORDS]810 unmodified lines811812813814815816817818819820821810 unmodified linesdef singular_to_plural(word):"""Convert singular words to plural using inflect."""plural = p.plural(word)return plural or worddef plural_to_singular(word):"""Convert plural word to singular using inflect."""return p.singular_noun(word) or wordplural_MATH_WORDS = [singular_to_plural(word) for word in MATH_WORDS]
handler.py+15-17
utils.py+5-1