• Stars
    star
    115
  • Rank 295,167 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created about 5 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TOEIC(Test of English for International Communication) solving using pytorch-pretrained-BERT model.

TOEIC-BERT

76% Correct rate with ONLY Pre-Trained BERT model in TOEIC!!

This is project as topic: TOEIC(Test of English for International Communication) problem solving using pytorch-pretrained-BERT model. The reason why I used huggingface's pytorch-pretrained-BERT model is for pre-training or to do fine-tune more easily. I've solved the only blank problem, not the whole problem. There are two types of blank issues:

  1. Selecting Correct Grammar Type.
Q) The music teacher had me _ scales several times.
  1. play (Answer)
  2. to play
  3. played
  4. playing
  1. Selecting Correct Vocabulary Type.
Q) The wet weather _ her from going playing tennis.
  1. interrupted
  2. obstructed
  3. impeded
  4. discouraged (Answer)

BERT Testing

  1. input
{
    "1" : {
        "question" : "Business experts predict that the upward trend is _ to continue until the end of next year.",
        "answer" : "likely",
        "1" : "potential",
        "2" : "likely",
        "3" : "safety",
        "4" : "seemed"
    }
}
  1. output
=============================
Question : Business experts predict that the upward trend is _ to continue until the end of next year.

Real Answer : likely

1) potential 2) likely 3) safety 4) seemed

BERT's Answer => [likely]

Why BERT?

In pretrained BERT, It contains contextual information. So It can find more contextual or grammatical sentences, not clear, a little bit. I was inspired by grammar checker from blog post.

Can We Use BERT as a Language Model to Assign a Score to a Sentence?

BERT uses a bidirectional encoder to encapsulate a sentence from left to right and from right to left. Thus, it learns two representations of each word-one from left to right and one from right to left-and then concatenates them for many downstream tasks.

Evaluation

I had evaluated with only pretrained BERT model(not fine-tuning) to check grammatical or lexical error. Above mathematical expression, X is a question sentence. and n is number of questions : {a, b, c, d}. C subset means answer candidate tokens : C of warranty is ['warrant', '##y']. V means total Vocabulary.

There's a problem with more than one token. I solved this problem by getting the average value of each tensor. ex) is being formed as ['is', 'being', 'formed']

Then, we find argmax in L_n(T_n).

predictions = model(question_tensors, segment_tensors)

# predictions : [batch_size, sequence_length, vocab_size]
predictions_candidates = predictions[0, masked_index, candidate_ids].mean()

Result of Evaluation.

Fantastic result with only pretrained BERT model

  • bert-base-uncased: 12-layer, 768-hidden, 12-heads, 110M parameters
  • bert-large-uncased: 24-layer, 1024-hidden, 16-heads, 340M parameters
  • bert-base-cased: 12-layer, 768-hidden, 12-heads , 110M parameters
  • bert-large-cased: 24-layer, 1024-hidden, 16-heads, 340M parameters

Total 7067 datasets: make non-deterministic with model.eval()

bert-base-uncased bert-base-cased bert-large-uncased bert-large-cased
Correct Num 5192 5398 5321 5148
Percent 73.46% 76.38% 75.29% 72.84%

Quick Start with Python pip Package.

Start with pip

$ pip install toeicbert

Run & Option

$ python -m toeicbert --model bert-base-uncased --file test.json
  • -m, --model : bert-model name in huggingface's pytorch-pretrained-BERT : bert-base-uncased, bert-large-uncased, bert-base-cased, bert-large-cased.

  • -f, --file : json file to evalution, see json format, test.json.

    key(question, 1, 2, 3, 4) is required options, but answer not.

    _ in question will be replaced to [MASK]

{
    "1" : {
        "question" : "The music teacher had me _ scales several times.",
        "answer" : "play",
        "1" : "play",
        "2" : "to play",
        "3" : "played",
        "4" : "playing"
    },
    "2" : {
        "question" : "The music teacher had me _ scales several times.",
        "1" : "play",
        "2" : "to play",
        "3" : "played",
        "4" : "playing"
    }
}

Author

  • Tae Hwan Jung(Jeff Jung) @graykode, Kyung Hee Univ CE(Undergraduate).
  • Author Email : [email protected]

Thanks for Hwan Suk Gang(Kyung Hee Univ.) for collecting Dataset(7114 datasets)

More Repositories

1

nlp-tutorial

Natural Language Processing Tutorial for Deep Learning Researchers
Jupyter Notebook
13,597
star
2

nlp-roadmap

ROADMAP(Mind Map) and KEYWORD for students those who have interest in learning NLP
3,160
star
3

distribution-is-all-you-need

The basic distribution probability Tutorial for Deep Learning Researchers
Python
1,596
star
4

gpt-2-Pytorch

Simple Text-Generator with OpenAI gpt-2 Pytorch Implementation
Python
927
star
5

xlnet-Pytorch

Simple XLNet implementation with Pytorch Wrapper
Jupyter Notebook
569
star
6

commit-autosuggestions

A tool that AI automatically recommends commit messages.
Python
381
star
7

modelsummary

All Model summary in PyTorch similar to `model.summary()` in Keras
Python
84
star
8

matorage

Matorage is tensor(multidimensional matrix) object storage manager for deep learning framework(Pytorch, Tensorflow V2, Keras)
Python
72
star
9

KorQuAD-beginner

Guide KorQuAD upload to leaderboard (EM 68.947 / F1 88.468) model which only use BERT-multilingual(single)
Python
41
star
10

aws-kubeflow

A guideline for basic use and installation of kubeflow in AWS.
Jupyter Notebook
37
star
11

vision-tutorial

Computer Vision Tutorial for Deep Learning Researchers
Python
33
star
12

DeepLearning-Study

This is repository for DeepLearning Study in Kyung Hee University
Python
27
star
13

DAC

Deep Adaptive Image Clustering Paper Implementation
Jupyter Notebook
25
star
14

horovod-ansible

Create Horovod cluster easily using Ansible
HCL
22
star
15

aws-kubeadm-terraform

create kubernetes cluster on AWS only typing 'terraform apply' on 3 minutes.
HCL
16
star
16

kubernetes-glusterfs-aws

file system clustering as glusterfs in kubernetes environment on aws platform
Shell
13
star
17

mlm-pipeline

mlm-pipeline is a cloud architecture that preprocesses the masked language model (mlm)
Python
10
star
18

linux0.11-kernel-code-review

The old Linux kernel source ver 0.11 review with line by line for OS lecture.
C
9
star
19

khuthon2018

λ”₯λŸ¬λ‹μ„ μ‚¬μš©ν•œ 맛집 뢄석 - 2018λ…„ 쿠톀(해컀톀)
JavaScript
8
star
20

projects

MY PROJECT LIST AT A GLANCE πŸŒˆπŸš€πŸ¦„
7
star
21

graykode.github.io

graykode's blog
Shell
4
star
22

ALGORITHM-MASTER

I LOVE ALGORITHM
C++
4
star
23

nlpblock

Use Abstractions Level Block for NLP with Pytorch
Python
3
star
24

intellij-foundry

Kotlin
3
star
25

ml-kubernetes-tutorial

very basic tutorial for who interesting in Machine Learning Serving with Docker, Kubernetes, Kubeflow
3
star
26

mnist-flow

This Project is only repository for solving AI Engineer Party
Python
3
star
27

modelaverage

tf-keras, make the average of model weight in same model.
Python
3
star
28

nonce-python

2019 github seminar in D.COM
HTML
2
star
29

nlp-advance

Simple Paper Implementation Code about all model after Attention is all you need(Transformer)
2
star
30

graykode

1
star
31

ohora

Jupyter Notebook
1
star