Skip to content

Instantly share code, notes, and snippets.

@AlisonDavey
Created September 20, 2019 17:32
Show Gist options
  • Save AlisonDavey/9c1060cc0c9d12ebd2a9042db054de6e to your computer and use it in GitHub Desktop.
Save AlisonDavey/9c1060cc0c9d12ebd2a9042db054de6e to your computer and use it in GitHub Desktop.
open_cloze_with_BERT.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {},
"cell_type": "markdown",
"source": "# Using BERT to solve 'open cloze' exercises\n\n@Data_sigh\n\nBERT (Bidirectional Encoder Representations from Transformers) with pretrained weights is loaded from the library of state-of-the-art pretrained models from HuggingFace\n\nBERT: Pre-training of Deep Bidirectional Transformers for Language Understanding\nhttps://arxiv.org/abs/1810.04805\n@article{devlin2018bert,\n title={BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding},\n author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},\n journal={arXiv preprint arXiv:1810.04805},\n year={2018}\n}\nhttps://github.com/google-research/bert\n\nhttps://github.com/huggingface/pytorch-transformers\n\nhttps://colab.research.google.com/github/pytorch/pytorch.github.io/blob/master/assets/hub/huggingface_pytorch-pretrained-bert_bert.ipynb\n\nBertTokenizer: to perform end-to-end tokenization, i.e. basic tokenization followed by WordPiece tokenization\nText normalization: Convert all whitespace characters to spaces, and (for the Uncased model) lowercase the input and strip out accent markers. E.g., John Johanson's, → john johanson's,.\nPunctuation splitting: Split all punctuation characters on both sides (i.e., add whitespace around all punctuation characters). Punctuation characters are defined as (a) Anything with a P* Unicode class, (b) any non-letter/number/space ASCII character (e.g., characters like $ which are technically not punctuation). E.g., john johanson's, → john johanson ' s ,\nWordPiece tokenization: Apply whitespace tokenization to the output of the above procedure, and apply WordPiece tokenization to each token separately. (Our implementation is directly based on the one from tensor2tensor, which is linked). E.g., john johanson ' s , → john johan ##son ' s ,\n\nBertForMaskedLM: BERT Transformer with the pre-trained masked language modelling head on top (fully pre-trained)"
},
{
"metadata": {
"_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19",
"_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5",
"trusted": false
},
"cell_type": "code",
"source": "from fastai.text import * \nfrom pytorch_transformers import BertTokenizer, BertForMaskedLM\nimport glob",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"_cell_guid": "79c7e3d0-c299-4dcb-8224-4455121ee9b0",
"_uuid": "d629ff2d2480ee46fbb7e2d37f6b5fab8052498a",
"trusted": false
},
"cell_type": "code",
"source": "bert_model_name=\"bert-base-uncased\" # Pretrained weights shortcut\ntokenizer = BertTokenizer.from_pretrained(bert_model_name, do_lower_case=True) # wordpiece tokenizer\nmaskedLM_model = BertForMaskedLM.from_pretrained(bert_model_name)\nmaskedLM_model.eval();",
"execution_count": 2,
"outputs": []
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "fnames = glob.glob(\"C:/Users/aliso/.fastai/data/cambridge_nlp/test/open_cloze/*.xlsx\") # test data",
"execution_count": 3,
"outputs": []
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "def exam_test_open_cloze(df_test, n=1):\n score = 0\n txt_before_gap = tokenizer.tokenize(df_test.text[0])\n txt_before_gap = ' '.join(txt_before_gap[-6:]) # no more than 6 tokens\n for i in range(len(df_test)-1): \n txt_after_gap = df_test.text[i+1]\n txt = '[CLS] ' + txt_before_gap + ' [MASK] ' + txt_after_gap + ' [SEP]'\n # Tokenized input\n tokens_txt = tokenizer.tokenize(txt)\n idx_tokens = [tokenizer.convert_tokens_to_ids(tokens_txt)]\n masked_idx = tokens_txt.index('[MASK]')\n segments_ids = [0] * masked_idx + [1] * (len(tokens_txt)-masked_idx)\n # Convert inputs to PyTorch tensors\n segments_tensors = torch.tensor(segments_ids)\n tokens_tensor = torch.tensor(idx_tokens)\n # Predict the missing token (indicated with [MASK]) with `BertForMaskedLM`\n with torch.no_grad(): preds = maskedLM_model(tokens_tensor, segments_tensors)\n preds_idx = [torch.argmax(preds[0][0, masked_idx,:]).item()]\n pred_token = tokenizer.convert_ids_to_tokens(preds_idx)[0]\n \n if pred_token in [',','.']: # Take second highest prediction if the first is punctuation\n preds[0][0,masked_idx,preds_idx]=0\n preds_idx = [torch.argmax(preds[0][0, masked_idx,:]).item()]\n pred_token = tokenizer.convert_ids_to_tokens(preds_idx)[0]\n \n if n==2:\n # Make two suggestions for each word\n preds[0][0,masked_idx,preds_idx]=0\n preds_idx = [torch.argmax(preds[0][0, masked_idx,:]).item()]\n pred_token2 = tokenizer.convert_ids_to_tokens(preds_idx)[0]\n pred_token = [pred_token, pred_token2] # propose 2 words\n\n print (df_test.text[i], \"[\", pred_token, \":\", df_test.answer[i], \"]\")\n \n actual_answer = list(df_test.answer[i].lower().split(\"'\"))\n if n==2:\n if (any(x == pred_token[0] for x in actual_answer) or any(x == pred_token[1] for x in actual_answer)):\n score +=1\n else:\n if pred_token in actual_answer:\n score +=1\n \n txt_before_gap = tokenizer.tokenize(txt_after_gap)\n txt_before_gap = ' '.join(txt_before_gap[-7:])\n \n print (df_test.text[len(df_test)-1])\n print (\"SCORE\", score, '/', len(df_test)-1 )\n return score",
"execution_count": 4,
"outputs": []
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "pd.set_option('display.max_colwidth', 150)\ndf_test = pd.read_excel(fnames[0])\ndf_test",
"execution_count": 5,
"outputs": [
{
"data": {
"text/html": "<div>\n<style scoped>\n .dataframe tbody tr th:only-of-type {\n vertical-align: middle;\n }\n\n .dataframe tbody tr th {\n vertical-align: top;\n }\n\n .dataframe thead th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>question</th>\n <th>answer</th>\n <th>text</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <td>0</td>\n <td>0.0</td>\n <td>as</td>\n <td>I work</td>\n </tr>\n <tr>\n <td>1</td>\n <td>9.0</td>\n <td>where</td>\n <td>a motorbike stunt rider - that is, I do tricks on my motorbike at shows. The Le Mans racetrack in France was</td>\n </tr>\n <tr>\n <td>2</td>\n <td>10.0</td>\n <td>so</td>\n <td>I first saw some guys doing motorbike stunts. I'd never seen anyone riding a motorbike using just the back wheel before and I was</td>\n </tr>\n <tr>\n <td>3</td>\n <td>11.0</td>\n <td>myself</td>\n <td>impressed I went straight home and taught</td>\n </tr>\n <tr>\n <td>4</td>\n <td>12.0</td>\n <td>in</td>\n <td>to do the same. It wasn't very long before I began to earn my living at shows performing my own motorbike stunts. I have a degree</td>\n </tr>\n <tr>\n <td>5</td>\n <td>13.0</td>\n <td>['which','that']</td>\n <td>mechanical engineering; this helps me to look at the physics</td>\n </tr>\n <tr>\n <td>6</td>\n <td>14.0</td>\n <td>['out','on','at']</td>\n <td>lies behind each stunt. In addition to being responsible for design changes to the motorbike, I have to work</td>\n </tr>\n <tr>\n <td>7</td>\n <td>15.0</td>\n <td>from</td>\n <td>every stunt I do. People often think that my work is very dangerous, but, apart</td>\n </tr>\n <tr>\n <td>8</td>\n <td>16.0</td>\n <td>any</td>\n <td>some minor mechanical problems happening occasionally during a stunt, nothing ever goes wrong. I never feel in</td>\n </tr>\n <tr>\n <td>9</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>kind of danger because I'm very experienced.</td>\n </tr>\n </tbody>\n</table>\n</div>",
"text/plain": " question answer \\\n0 0.0 as \n1 9.0 where \n2 10.0 so \n3 11.0 myself \n4 12.0 in \n5 13.0 ['which','that'] \n6 14.0 ['out','on','at'] \n7 15.0 from \n8 16.0 any \n9 NaN NaN \n\n text \n0 I work \n1 a motorbike stunt rider - that is, I do tricks on my motorbike at shows. The Le Mans racetrack in France was \n2 I first saw some guys doing motorbike stunts. I'd never seen anyone riding a motorbike using just the back wheel before and I was \n3 impressed I went straight home and taught \n4 to do the same. It wasn't very long before I began to earn my living at shows performing my own motorbike stunts. I have a degree \n5 mechanical engineering; this helps me to look at the physics \n6 lies behind each stunt. In addition to being responsible for design changes to the motorbike, I have to work \n7 every stunt I do. People often think that my work is very dangerous, but, apart \n8 some minor mechanical problems happening occasionally during a stunt, nothing ever goes wrong. I never feel in \n9 kind of danger because I'm very experienced. "
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "exam_test_open_cloze(pd.read_excel(fnames[0]), n=1)",
"execution_count": 6,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "I work [ as : as ]\na motorbike stunt rider - that is, I do tricks on my motorbike at shows. The Le Mans racetrack in France was [ where : where ]\nI first saw some guys doing motorbike stunts. I'd never seen anyone riding a motorbike using just the back wheel before and I was [ so : so ]\nimpressed I went straight home and taught [ myself : myself ]\nto do the same. It wasn't very long before I began to earn my living at shows performing my own motorbike stunts. I have a degree [ in : in ]\nmechanical engineering; this helps me to look at the physics [ that : ['which','that'] ]\nlies behind each stunt. In addition to being responsible for design changes to the motorbike, I have to work [ on : ['out','on','at'] ]\nevery stunt I do. People often think that my work is very dangerous, but, apart [ from : from ]\nsome minor mechanical problems happening occasionally during a stunt, nothing ever goes wrong. I never feel in [ any : any ]\nkind of danger because I'm very experienced.\nSCORE 9 / 9\n"
},
{
"data": {
"text/plain": "9"
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "total_score = 0\nfor fname in list(fnames): \n print ()\n print (fname.split('\\\\')[-1])\n df_test = pd.read_excel(fname)\n score = exam_test_open_cloze(df_test, n=1)\n total_score+=score\nprint (\"TOTAL\", total_score, ' in ', len(fnames), ' tests', 100*total_score/(9*len(fnames)), '%')",
"execution_count": 7,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "\nB2_sample_paper_1_part_2_first.xlsx\nI work [ as : as ]\na motorbike stunt rider - that is, I do tricks on my motorbike at shows. The Le Mans racetrack in France was [ where : where ]\nI first saw some guys doing motorbike stunts. I'd never seen anyone riding a motorbike using just the back wheel before and I was [ so : so ]\nimpressed I went straight home and taught [ myself : myself ]\nto do the same. It wasn't very long before I began to earn my living at shows performing my own motorbike stunts. I have a degree [ in : in ]\nmechanical engineering; this helps me to look at the physics [ that : ['which','that'] ]\nlies behind each stunt. In addition to being responsible for design changes to the motorbike, I have to work [ on : ['out','on','at'] ]\nevery stunt I do. People often think that my work is very dangerous, but, apart [ from : from ]\nsome minor mechanical problems happening occasionally during a stunt, nothing ever goes wrong. I never feel in [ any : any ]\nkind of danger because I'm very experienced.\nSCORE 9 / 9\n\nB2_sample_paper_2_part_2_first.xlsx\nIn the 15th century, Europeans knew nothing of the chilli pepper, but they held black pepper in high regard and had used it in cooking [ in : since ]\nGreek and Roman times. Ships travelling east brought the black pepper from the Spice Islands in South East Asia but this [ took : took ]\na long time. In 1492, Christopher Columbus was asked to find a shorter route to the Spice Islands, going westwards [ rather : rather ]\nthan eastwards, and so he set [ sail : ['off','out','sail'] ]\nfrom Spain across the Atlantic Ocean. Columbus didn't succeed [ in : in ]\nfinding the Spice Islands but he [ did : did ]\nmanage to discover the Americas. There he [ came : came ]\nacross another pepper; the chilli, which had been used in cooking in South America for thousands of years. Soon [ after : after ]\nColumbus's discovery, large quantities of chillies were being shipped back to Spain from the Caribbean. Later, people realised that chillies would actually grow in southern Europe and it wasn't long before fresh chillies were [ for : ['on','for'] ]\nsale in European markets.\nSCORE 8 / 9\n\nC1_sample_paper_1_part_2_advanced.xlsx\nThe truth [ is : is ]\nnobody really knows how language first began. Did we all start talking at around the same time [ because : because ]\nof the manner in which our brains had begun to develop? Although there is a lack of clear evidence, people have come up with various theories about the origins of language. One recent theory is that human beings have evolved in [ such : such ]\na way that we are programmed for language from the moment of birth. In [ other : other ]\nwords, language came about as a result of an evolutionary change in our brains at some stage. Language [ may : ['could','may','might'] ]\nwell be programmed into the brain but, [ despite : despite ]\nthis, people still need stimulus from others around them. From studies, we know that [ if : ['if','when','whenever'] ]\nchildren are isolated from human contact and have not learnt to construct sentences before they are ten, it is doubtful they will ever do so. The research shows, if [ nothing : ['nothing','little'] ]\nelse, that language is a social activity, not something invented [ in : in ]\nisolation.\nSCORE 9 / 9\n\nC1_sample_paper_2_part_2_advanced.xlsx\nMost people find change unsettling and difficult to adapt [ it : to ]\n. Many societies have experienced [ such : such ]\nrapid change in the early years of the 21st century that life can feel very daunting [ several : at ]\ntimes. Various commentators have [ put : put ]\nforward suggestions for coping with change on a personal level. One suggestion involves thinking of three solutions to a problem, rather [ than : than ]\ntwo. Apparently, many people faced [ social : ['with', 'by'] ]\nchange respond by considering two possible courses of action, but invariably tend to reject both of these. However, thinking instead of three potential solutions is a strategy which, according to research, provides a reliable way of finding a solution to the initial problem. Another strategy advocates learning to avoid set patterns of behaviour. Something simple, [ or : like ]\ntaking another route to work at [ least : least ]\nonce a week, is seen as encouraging confidence in the face of uncertainty. [ despite : Despite ]\nthe simplicity of these ideas, they nevertheless help people prepare mentally to manage major change if necessary.\nSCORE 5 / 9\n\nC2_sample_paper_1_part_2_prof.xlsx\nFor many people, mobile email is a habit they couldn't give up even [ if : if ]\nthey wanted to. And [ why : why ]\nshould they want to? [ after : after ]\nall, the ability to send and receive emails from a mobile device means they can stay in touch with colleagues, friends and family, whether they're standing in a queue at the supermarket, downing a quick cup of coffee in [ business : between ]\nmeetings or killing [ someone : time ]\nbefore a flight. It's fair to say that access to email while [ on : on ]\nthe move had done much to whet appetites for other kinds of collaborative tools. What's [ more : more ]\n, there's a whole new way of working that has opened up in recent years and, [ as : as ]\na result, there's a general expectation that efficiency and productivity don't necessarily take [ place : place ]\nwithin the four walls of an organisation's physical offices.\nSCORE 7 / 9\n\nC2_sample_paper_2_part_2_prof.xlsx\nIt is often pointed [ out : out ]\njust how rare it is for people to communicate by putting pen to paper. Many of us have friends [ whose : whose ]\nhandwriting is unfamiliar to us because we have never seen it. This is [ not : not ]\nto say that we should forgo all the advantages of electronic communication, but what it has led to is that some British schools no [ longer : longer ]\nteach handwriting, on the grounds that all children now have access to computers. But can this be justified? [ after : after ]\nall, nobody thinks that learning to ride a bike means losing the pleasure of running. One intriguing aspect of handwriting is what, [ if : if ]\nanything, it tells you about a person. It has been suggested that it can reveal various personal qualities, and even someone's health and intelligence. While some feel this is [ going : going ]\ntoo far, it is also true that because every individual has a distinctive style, handwriting is, in [ all : all ]\nprobability, expressing something about them. However, studying handwriting is [ nowhere : nowhere ]\nnear being accepted as a proper science.\nSCORE 9 / 9\n\nC2_sample_paper_3_part_2_prof.xlsx\nIn fiction robots have a personality, [ but : but ]\nreality is disappointingly different. Although sophisticated [ robots : enough ]\nto assemble cars and assist during complex surgery, modern robots are dumb automatons, [ capable : incapable ]\nof striking up relationships with their human operators. However, change is [ on : on ]\nthe horizon. Engineers argue that, as robots begin to make [ themselves : up ]\na bigger part of society, they will need a way to interact with humans. To this end they will need artificial personalities. The big question is this: what does a synthetic companion need to have so that you want to engage [ in : with ]\nit over a long period of time? Phones and computers have already shown the [ extent : ['extent','degree'] ]\nto which people can develop relationships with inanimate electronic objects. Looking further [ on : ['ahead','forward'] ]\n, engineers envisage robots helping around the house, integrating with the web to place supermarket orders using email. Programming the robot with a human-like persona and [ giving : giving ]\nit the ability to learn its user's preferences, will help the person feel at ease with it. Interaction with such a digital entity in this context is more natural than sitting with a mouse and keyboard.\nSCORE 4 / 9\nTOTAL 51 in 7 tests 80.95238095238095 %\n"
}
]
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "total_score = 0\nfor fname in list(fnames): \n print ()\n print (fname.split('\\\\')[-1])\n df_test = pd.read_excel(fname)\n score = exam_test_open_cloze(df_test, n=2)\n total_score+=score\nprint (\"TOTAL\", total_score, ' in ', len(fnames), ' tests', 100*total_score/(9*len(fnames)), '%')",
"execution_count": 8,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "\nB2_sample_paper_1_part_2_first.xlsx\nI work [ ['as', 'like'] : as ]\na motorbike stunt rider - that is, I do tricks on my motorbike at shows. The Le Mans racetrack in France was [ ['where', 'when'] : where ]\nI first saw some guys doing motorbike stunts. I'd never seen anyone riding a motorbike using just the back wheel before and I was [ ['so', 'pretty'] : so ]\nimpressed I went straight home and taught [ ['myself', 'others'] : myself ]\nto do the same. It wasn't very long before I began to earn my living at shows performing my own motorbike stunts. I have a degree [ ['in', 'of'] : in ]\nmechanical engineering; this helps me to look at the physics [ ['that', 'which'] : ['which','that'] ]\nlies behind each stunt. In addition to being responsible for design changes to the motorbike, I have to work [ ['on', 'with'] : ['out','on','at'] ]\nevery stunt I do. People often think that my work is very dangerous, but, apart [ ['from', 'of'] : from ]\nsome minor mechanical problems happening occasionally during a stunt, nothing ever goes wrong. I never feel in [ ['any', 'that'] : any ]\nkind of danger because I'm very experienced.\nSCORE 9 / 9\n\nB2_sample_paper_2_part_2_first.xlsx\nIn the 15th century, Europeans knew nothing of the chilli pepper, but they held black pepper in high regard and had used it in cooking [ ['in', 'during'] : since ]\nGreek and Roman times. Ships travelling east brought the black pepper from the Spice Islands in South East Asia but this [ ['took', 'was'] : took ]\na long time. In 1492, Christopher Columbus was asked to find a shorter route to the Spice Islands, going westwards [ ['rather', 'more'] : rather ]\nthan eastwards, and so he set [ ['sail', 'out'] : ['off','out','sail'] ]\nfrom Spain across the Atlantic Ocean. Columbus didn't succeed [ ['in', 'at'] : in ]\nfinding the Spice Islands but he [ ['did', 'cannot'] : did ]\nmanage to discover the Americas. There he [ ['came', 'stumbled'] : came ]\nacross another pepper; the chilli, which had been used in cooking in South America for thousands of years. Soon [ ['after', 'before'] : after ]\nColumbus's discovery, large quantities of chillies were being shipped back to Spain from the Caribbean. Later, people realised that chillies would actually grow in southern Europe and it wasn't long before fresh chillies were [ ['for', 'on'] : ['on','for'] ]\nsale in European markets.\nSCORE 8 / 9\n\nC1_sample_paper_1_part_2_advanced.xlsx\nThe truth [ ['is', ':'] : is ]\nnobody really knows how language first began. Did we all start talking at around the same time [ ['because', 'regardless'] : because ]\nof the manner in which our brains had begun to develop? Although there is a lack of clear evidence, people have come up with various theories about the origins of language. One recent theory is that human beings have evolved in [ ['such', 'so'] : such ]\na way that we are programmed for language from the moment of birth. In [ ['other', 'many'] : other ]\nwords, language came about as a result of an evolutionary change in our brains at some stage. Language [ ['may', 'might'] : ['could','may','might'] ]\nwell be programmed into the brain but, [ ['despite', 'in'] : despite ]\nthis, people still need stimulus from others around them. From studies, we know that [ ['if', 'because'] : ['if','when','whenever'] ]\nchildren are isolated from human contact and have not learnt to construct sentences before they are ten, it is doubtful they will ever do so. The research shows, if [ ['nothing', 'anything'] : ['nothing','little'] ]\nelse, that language is a social activity, not something invented [ ['in', 'by'] : in ]\nisolation.\nSCORE 9 / 9\n\nC1_sample_paper_2_part_2_advanced.xlsx\nMost people find change unsettling and difficult to adapt [ ['it', 'here'] : to ]\n. Many societies have experienced [ ['such', 'so'] : such ]\nrapid change in the early years of the 21st century that life can feel very daunting [ ['several', 'multiple'] : at ]\ntimes. Various commentators have [ ['put', 'brought'] : put ]\nforward suggestions for coping with change on a personal level. One suggestion involves thinking of three solutions to a problem, rather [ ['than', 'like'] : than ]\ntwo. Apparently, many people faced [ ['social', 'climate'] : ['with', 'by'] ]\nchange respond by considering two possible courses of action, but invariably tend to reject both of these. However, thinking instead of three potential solutions is a strategy which, according to research, provides a reliable way of finding a solution to the initial problem. Another strategy advocates learning to avoid set patterns of behaviour. Something simple, [ ['or', 'and'] : like ]\ntaking another route to work at [ ['least', 'work'] : least ]\nonce a week, is seen as encouraging confidence in the face of uncertainty. [ ['despite', 'given'] : Despite ]\nthe simplicity of these ideas, they nevertheless help people prepare mentally to manage major change if necessary.\nSCORE 5 / 9\n\nC2_sample_paper_1_part_2_prof.xlsx\nFor many people, mobile email is a habit they couldn't give up even [ ['if', 'when'] : if ]\nthey wanted to. And [ ['why', 'what'] : why ]\nshould they want to? [ ['after', 'above'] : after ]\nall, the ability to send and receive emails from a mobile device means they can stay in touch with colleagues, friends and family, whether they're standing in a queue at the supermarket, downing a quick cup of coffee in [ ['business', 'planning'] : between ]\nmeetings or killing [ ['someone', 'people'] : time ]\nbefore a flight. It's fair to say that access to email while [ ['on', 'making'] : on ]\nthe move had done much to whet appetites for other kinds of collaborative tools. What's [ ['more', 'worse'] : more ]\n, there's a whole new way of working that has opened up in recent years and, [ ['as', 'for'] : as ]\na result, there's a general expectation that efficiency and productivity don't necessarily take [ ['place', 'places'] : place ]\nwithin the four walls of an organisation's physical offices.\nSCORE 7 / 9\n\nC2_sample_paper_2_part_2_prof.xlsx\nIt is often pointed [ ['out', 'to'] : out ]\njust how rare it is for people to communicate by putting pen to paper. Many of us have friends [ ['whose', '.'] : whose ]\nhandwriting is unfamiliar to us because we have never seen it. This is [ ['not', 'fair'] : not ]\nto say that we should forgo all the advantages of electronic communication, but what it has led to is that some British schools no [ ['longer', 'more'] : longer ]\nteach handwriting, on the grounds that all children now have access to computers. But can this be justified? [ ['after', 'at'] : after ]\nall, nobody thinks that learning to ride a bike means losing the pleasure of running. One intriguing aspect of handwriting is what, [ ['if', 'almost'] : if ]\nanything, it tells you about a person. It has been suggested that it can reveal various personal qualities, and even someone's health and intelligence. While some feel this is [ ['going', 'not'] : going ]\ntoo far, it is also true that because every individual has a distinctive style, handwriting is, in [ ['all', 'high'] : all ]\nprobability, expressing something about them. However, studying handwriting is [ ['nowhere', 'very'] : nowhere ]\nnear being accepted as a proper science.\nSCORE 9 / 9\n\nC2_sample_paper_3_part_2_prof.xlsx\nIn fiction robots have a personality, [ ['but', 'and'] : but ]\nreality is disappointingly different. Although sophisticated [ ['robots', 'enough'] : enough ]\nto assemble cars and assist during complex surgery, modern robots are dumb automatons, [ ['capable', 'incapable'] : incapable ]\nof striking up relationships with their human operators. However, change is [ ['on', 'over'] : on ]\nthe horizon. Engineers argue that, as robots begin to make [ ['themselves', 'up'] : up ]\na bigger part of society, they will need a way to interact with humans. To this end they will need artificial personalities. The big question is this: what does a synthetic companion need to have so that you want to engage [ ['in', 'with'] : with ]\nit over a long period of time? Phones and computers have already shown the [ ['extent', 'degree'] : ['extent','degree'] ]\nto which people can develop relationships with inanimate electronic objects. Looking further [ ['on', 'further'] : ['ahead','forward'] ]\n, engineers envisage robots helping around the house, integrating with the web to place supermarket orders using email. Programming the robot with a human-like persona and [ ['giving', 'with'] : giving ]\nit the ability to learn its user's preferences, will help the person feel at ease with it. Interaction with such a digital entity in this context is more natural than sitting with a mouse and keyboard.\nSCORE 8 / 9\nTOTAL 55 in 7 tests 87.3015873015873 %\n"
}
]
},
{
"metadata": {
"trusted": false
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.6.7",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "open_cloze_with_BERT.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment