Our team name is : Team A
Members: @anie @radpet @kuzman @vicky @rseoane @greenhat
The Ontotext Case – ‘Luke, I am Your Father’
“Well, if droids could think, there’d be none of us here, would there?” — Obi-Wan Kenobi
The objective of our task is extract parent-subsidiary relationship in text. For example, a news from techcruch says this, ‘Remember those rumors a few weeks ago that Google was looking to acquire the plug-and-play security camera company, Dropcam? Yep. It just happened.’. Now from this sentence we can infer that Dropcam is a subsidiary of Google. But there are million of companies and several million articles talking about them. A Human being can be tired of doing even 10! Trust me 😉 We have developed some cool Machine learning models spanning from classical algorithms to Deep Neural network do this for you. There is a bonus! We just do not give you probabilities. We also give out that sentences that triggered the algorithm to make the inference! For instance when it says Orcale Corp is the parent of Microsys it can also return that the sentence in its corpus ‘Oracle Corp’s Microsys customer support portal was seen communicating with a server’, triggered its prediction.
The aim of the current paper is to explore the idea of optimizing searching within large text collections by teaching an AI to read text and identify parent-subsidiary relations between relevant entities. To achieve this goal the data provided by Ontotext is analyzed and incorporated into models in an attempt to extract simple principles and to offer accurate predictions.
1. Business understanding
At present it takes a lot of resources to assist Ontotext’s clients in their search experience with large text collections – it is both expensive and time-consuming to prepare the necessary annotations. The end goal of the paper is to present a simplified process for obtaining text with annotations, which will enable clients to perform searches more efficiently and ultimately the cost of attaining such data selections will be reduced.
Other important question that has to be answered is whether Precision or Recall is important for the current business. In case if the business needs a very high recall and someone can manually verify the relationships suggested by the algorithm, one of our final models also gives Onto Text an opportunity to retrieve those sentences which triggered the algorithm prediction, this will result in a cost cut even if manual intervention is needed.
One of the main lessons that we learned from this project is that the training data is considerably different from the test data especially in terms of the average number of articles per parent-subsidiary pair and issues discussed, which created a lot of trouble in modeling RNNs. Therefore it is better to have a considerable amount of training data from the actual test data source (which is private source that only Onto text has access to) itself labeled (maybe from Amazon Mechanical Turk) to quickly improve the model which will cut down a considerable cost for the company, as the Data science team is more expensive than AMT 😉 .
2. Project Plan
The core idea of the team to start with simpler models which can be used a baseline and then consequently to build upon it more complicated models.
The project spans over multiple stages, the main ones being:
- Data exploration and Preprocessing
- Augmentation of the existing set with the use of NLG APIs as well as Coreference resolution of entities
- Classical machine learning techniques (TF-IDF, Logistic Regression, SVM, Naive Bayes)
- Neural Networks
3. Data description
The given data consists of 4 columns with information on a parent and subsidiary company, a text snippet containing information on the two companies and a final column with true and false indicators, showing whether there is a positive or negative parent-subsidiary relationship between the entities considered.
There are a total of 89 452 observations in the training dataset. In terms of entities – 451 unique companies are included in the dataset as a whole and there is a difference in the number of unique parent companies relative to that of subsidiary ones:
Several steps were taken in order to clean the data.
Firstly duplicate rows were addressed – their total number is 10 069. For the purposes of the analysis only unique rows were considered and thus these observations were excluded.
Some issues were discovered in the snippet column – company names sometimes appear concatenated with other words, which leads to the formation of non-existent words that pollute the data. The issue was resolved by including extra intervals, preceding and following every company, within the snippet column.
In addition, 200 instances of articles with mention of only one company within the context of a given pair were identified. For simplification, they were ignored when considering their position as a feature.
The length distribution of each snippet is examined – both in terms of characters and words.
There are 62 881 instances with a negative relationship among companies while in 26 571 cases parent-subsidiary relations score as positive.
However, we failed to implement all data insights we wanted but we created a short notebook located here to illustrate the ideas. You can visit it by using the link below.
4. Data preparation
Part of the data selection process involves augmentation of the existing set via NLG APIs. Given a data row, values in the first three columns are maintained while the fourth column (text snippet) is processed through a “spintext” tool to generate variations that maintain the same relationships between entities, but where sentence order and nouns have been changed. By following this approach the NN may be trained so as to understand the relationships without relying on specific words. Another approach we didn’t try but was appealing was to use various translate API’s and receive paraphrased sentences with more or less same meaning. For example transitions from en->fr->en or en->de->en and en->es->en would generate enough diversity. We can also apply this to a sample from the test set and create additional variants of the sample that may be recognized by the classifier easier. If you are interested you can read more at
Co-reference resolution of entities was planned to be an additional feature for our models but we have not reached that stage yet.
The idea is to use coreference resolution in the preprocessing in order to replace coreferences like “they” with the respected company names. For example:
“To sweeten its new unlimited data offering, AT&T said that existing DirecTV or U-Verse customers who don’t subscribe to its wireless service can get $500 if they switch to the AT&T Unlimited Plan with an eligible trade-in, and buy a smartphone on AT&T Next.”
could be viewed as:
“To sweeten AT&T new unlimited data offering, AT&T said that existing DirecTV or U-Verse customers who don’t subscribe to AT&T wireless service can get $500 if DirecTV or U-Verse customers who don’t subscribe to its wireless service switch to the AT&T Unlimited Plan with an eligible trade-in, and buy a smartphone on AT&T Next.”
That way the model can detect relationships not only based on the company entity but also based on references elsewhere in the text.
In order to achieve this, a Stanford CoreNLP server(https://stanfordnlp.github.io/CoreNLP/corenlp-server.html) can be utilized. Furthermore, coreferences that do not point to companies are more or less pointless and could be discarded.
5. Classical machine learning
For the purposes of the analysis and training our models the data was split into three – a train set (with 70% of the data), on which models are trained, dev portion (being 20% of the data) – on which hyper parameter optimization is performed and a test set (with 10 % of the data), on which final test is run.
6. The Attentive Recurrent Neural Network
Although the data given to us has several snippets corresponding to each parent-subsidy pair, only some of the snippets reveal the actual parent-subsidiary relationship. Therefore we felt that concatenating the snippets corresponding to each pair into one single article and then training can give the model more information about which text snippet actually reveals the parent-subsidy relationship. (Please check Data preparation step 1 for more info.). Therefore from 79383 rows of relationship in the training data we end up in 952 rows of relationship.
In each text snippet irrespective of the real name of the companies, the context around it offers information on the directed parent-subsidiary relationship. Hence in each text snippet we replaced the corresponding parent company and subsidiary company with alias ‘company1’ and ‘company2’.
It is to be noted that the number of text snippets corresponding to each pair in the training data varied largely from some companies like Google and YouTube having approximately 4000 snippets to smaller companies having 2 or 3 snippets. Such a huge variance created big troubles in the test data which will be explained later.
- Each snippet corresponding to a parent-subsidiary relationship is consider as a single sentence (although there may be grammatically more sentences). And all the snippets (sentences) corresponding to a pair is considered as a document. Therefore this problem is now transformed into a document classification problem.
- As RNNs in tensorflow need sequences of equal length the sequences are padded/truncated to form a constant length.
- Word vectors are trained using gensim from the training corpus sentences.
- We use 750 documents (pairs) for training and 200 for validation
- Each word in a sentence is represented by the corresponding word vector and all the words in a sentence is concatenated sequentially as the input to the Bidirectional GRU.
- The GRU outputs a vector at each timestep (in our case for each word).
- Now we use an attention network which learns weights to for a linear combination of the GRU outputs. The output of the attention network is Sentence vector which represents a sentence.
- Now all the sentence vectors from a document is combined again with another attention network to form a document vector. Note there is no RNN at the second level because the order of sentences doesn’t influence the parent-subsidiary relationship
From the two snippets, ‘Google acquired Youtube’ and ‘Google DSS hackathon to watch its YouTube live’, for this particular task we know that the model should learn that the first sentence is more important than the second sentence and hence we can see a thicker arrow (meaning more weights) has to be given to the first sentence and also in the first sentence the word ‘acquired’, is more important than the other words.
The objective of the neural network is to model this.
The model is capable to taking all the articles corresponding to two companies as input and it gives out a probability of company 2 is a subsidiary of company 1 based on the text snippets.
In addition to this the model as returns important sentences which triggered its prediction. For example
from the test set we can see, a sample output
We can see that the model predicted the important sentence amidst several irrelevant sentences
The predicted parent-subsidiary pairs are:
0 Danaher_Corporation Pall_Corporation
1 Alibaba_Group AutoNavi
2 Berkshire_Hathaway NV_Energy
3 UniCredit HypoVereinsbank
4 Oracle_Corporation MICROS_Systems
5 Boeing Liquid_Robotics
6 RightNow_Technologies Oracle_Corporation
7 Walmart Walmart_de_México_y_Centroamérica
8 Boeing Pfizer
9 CareFusion Becton_Dickinson
10 Unocal_Corporation Chevron_Corporation
11 Marathon_Oil U.S._Steel
12 Citigroup Boeing
13 Citigroup Bank_Handlowy
14 Comcast Paramount_Pictures
15 Morgan_Stanley AT&T
16 Disney_Vacation_Club The_Walt_Disney_Company
17 Tencent HBO
18 AT&T Fullscreen_(company)
19 Singapore_Airlines Boeing
20 Alere Abbott_Laboratories
And the results from the NN that (@radpet) created can be seen here:
This confusion matrix is based on the predictions that were made on the split used for testing (10% of whole train data) and the network haven’t seen them. *Sadly I lost the tokenizer of this model and I attach pretrained model without change (only random luck with the weight initialization that makes the model scores a bit better on test split)
Before model selection took place two approaches were considered for expressing any given company pair – either to present the parent and subsidiary as an ordered pair of 0 and 1, while specifying that different order translates to a different pair; or to display them as “company1” and “company2” and use this representation within the snippet portion.
Classical machine learning – the key idea is to vectorize the text (as well as to add a TF-IDF score) and include it as a feature; company names are removed as such from the text and are instead assigned specific labels such as X and Y (in fact this is the chosen solution to the pair dilemma described above); they are then included and it is examined whether overfitting ensues as a result.
- Bag of words or TF-IDF with SVM
- TF-IDF with Naive-Bayes
- TF-IDF with Logistic Regression
Two architectures were applied:
- Architecture 1: each pair of companies and its respective snippet text is considered as a separate sample, which is fed into the NN. (@radpet) .
More info at https://github.com/radpet/team_a/blob/master/Radi/LSTM%26CNN.ipynb
- Architecture 2: grouping is performed – the snippet portions are concatenated based on their underlying unique company pairs and this is how NN results are returned. (@vicky). More info at https://github.com/radpet/team_a/tree/master/vicky
In order to evaluate the results obtained the F1 score is considered rather than the accuracy. By doing so the ratio of negative to positive responses does not have such a significant effect as in the accuracy one. Most of the models implemented come with metric evaluation that consist of confusion matrix and score.
VI. Our Contributors
- The state of the art man: @vicky
- Iterative approach with classical machine learning techniques to find a fast baseline and neural network enthusiast: @radpet
- The hyperparameter tuner of Logistic Regression and LinearSVM: @greenhat
- Data scrapers: @rseone and @kuzman
- Data support & article expert: @anie
Warning: This article is the result of Team-A’s collective efforts