suolyer commited on
Commit
f9cf421
1 Parent(s): b3a3dbe

Add introduction about unimc

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -446,7 +446,7 @@ class UniMCPredict:
446
  batch = [self.data_model.train_data.encode(
447
  sample) for sample in batch_data]
448
  batch = self.data_model.collate_fn(batch)
449
- # batch = {k: v.cuda() for k, v in batch.items()}
450
  _, _, logits = self.model.model(**batch)
451
  soft_logits = torch.nn.functional.softmax(logits, dim=-1)
452
  logits = torch.argmax(soft_logits, dim=-1).detach().cpu().numpy()
@@ -695,7 +695,13 @@ def main():
695
  model = load_model('IDEA-CCNL/Erlangshen-UniMC-RoBERTa-110M-Chinese')
696
  else:
697
  model = load_model('IDEA-CCNL/Erlangshen-UniMC-Albert-235M-English')
698
-
 
 
 
 
 
 
699
  st.info("Please input the following information「请输入以下信息...」")
700
  model_type = st.selectbox('Select task type「选择任务类型」',['Text classification「文本分类」','Sentiment「情感分析」','Similarity「语义匹配」','NLI 「自然语言推理」','Multiple Choice「多项式阅读理解」'])
701
  form = st.form("参数设置")
@@ -706,7 +712,7 @@ def main():
706
  else:
707
  sentences = form.text_area("Please input the context「请输入句子」", text_dict_en[model_type])
708
  question = form.text_input("Please input the question「请输入问题(不输入问题也可以)」", question_dict_en[model_type])
709
- choice = form.text_input("Please input the label(split by ‘;’)「输入标签(以中文;分割)」", choice_dict_en[model_type])
710
 
711
  form.form_submit_button("Submit「点击一下,开始预测!」")
712
 
@@ -724,7 +730,8 @@ def main():
724
 
725
 
726
  start=time.time()
727
- result = model.predict(data, cuda=False)
 
728
  st.success(f"Prediction is successful, consumes {str(time.time()-start)} seconds")
729
  st.json(result[0])
730
 
 
446
  batch = [self.data_model.train_data.encode(
447
  sample) for sample in batch_data]
448
  batch = self.data_model.collate_fn(batch)
449
+ batch = {k: v.to(self.model.model.device) for k, v in batch.items()}
450
  _, _, logits = self.model.model(**batch)
451
  soft_logits = torch.nn.functional.softmax(logits, dim=-1)
452
  logits = torch.argmax(soft_logits, dim=-1).detach().cpu().numpy()
 
695
  model = load_model('IDEA-CCNL/Erlangshen-UniMC-RoBERTa-110M-Chinese')
696
  else:
697
  model = load_model('IDEA-CCNL/Erlangshen-UniMC-Albert-235M-English')
698
+
699
+ st.markdown("""
700
+ UniMC 核心思想是将自然语言理解任务转化为 multiple choice 任务,其通过控制位置编码和attention mask来让模型可以直接复用 MaskLM head 的参数。这使得 UniMC 仅仅使用 multiple choice 数据集训练就可以超越千亿参数模型在zero-shot场景下。在中文数据集中,UniMC 同样超越了其他模型,获得了FewCLUE和ZeroCLUE两个榜单的第一。
701
+
702
+ The core idea of UniMC is to convert the natural language understanding task into a multiple choice task, which allows the model to directly reuse the parameters of the MaskLM head by controlling the position encoding and attention mask. This enables UniMC to surpass 100 billion parameter models in zero-shot scenarios just by training with multiple choice datasets. In the Chinese dataset, UniMC also surpassed other models and won the first place in both FewCLUE and ZeroCLUE.
703
+ """)
704
+
705
  st.info("Please input the following information「请输入以下信息...」")
706
  model_type = st.selectbox('Select task type「选择任务类型」',['Text classification「文本分类」','Sentiment「情感分析」','Similarity「语义匹配」','NLI 「自然语言推理」','Multiple Choice「多项式阅读理解」'])
707
  form = st.form("参数设置")
 
712
  else:
713
  sentences = form.text_area("Please input the context「请输入句子」", text_dict_en[model_type])
714
  question = form.text_input("Please input the question「请输入问题(不输入问题也可以)」", question_dict_en[model_type])
715
+ choice = form.text_input("Please input the label(split by ‘;’)「输入标签(以英文;分割)」", choice_dict_en[model_type])
716
 
717
  form.form_submit_button("Submit「点击一下,开始预测!」")
718
 
 
730
 
731
 
732
  start=time.time()
733
+ is_cuda= True if torch.cuda.is_available() else False
734
+ result = model.predict(data, cuda=is_cuda)
735
  st.success(f"Prediction is successful, consumes {str(time.time()-start)} seconds")
736
  st.json(result[0])
737