How do I implement a knowledge base in a Huggingface model? - bert-language-model

I made a knowledge base using COMET on the Atomic knowledge graph, using this tutorial.
I would like to include this knowledge in a regular pre-trained BERT model from HuggingFace to see how the model with access to this knowledge performs on a different task (sentiment analysis).
I saved the generated tuples from COMET in a pickle file.
Thanks!

Related

Using spaCy for finetuning a NER model in spaCy 3.0

I want to use en_core_web_trf model in spaCy library for Named entity recognition. However, the guide for training a custom model does not contain information for finetuning a pretrained model.
How can one finetune an NER model in spaCy v3.0?
It's recommended you train your NER component from scratch rather than fine-tuning the existing model, because fine-tuning the existing model is prone to catastrophic forgetting. Note that even if your NER component is trained from scratch, you're still using the Transformer as a starting point, so you aren't starting from nothing.
More details about why not to re-train the existing NER, and how to do it if you want to, are in the FAQ. There are also many threads about this topic in the Discussion in general.

How can i use BERT fo machine Translation?

I got a big problem. For my bachelor thesis I have to make a machine tranlation model with BERT.
But I am not getting anywhere right now.
Do you know a documentation or something that can help me here?
I have read some papers in that direction but maybe there is a documentation or tutorial that can help me.
For my bachelor thesis I have to translate from a summary of a text into a title.
I hope someone can help me.
BERT is not a machine translation model, BERT is designed to provide a contextual sentence representation that should be useful for various NLP tasks. Although there exist ways how BERT can be incorporated into machine translation (https://openreview.net/forum?id=Hyl7ygStwB), it is not an easy problem and there are doubts if it really pays off.
From your question, it seems that you are not really machine translation, but automatic summarization. Similarly to machine translation, it can be approached using sequence-to-sequence models, but we do not call it translation in NLP.
For sequence-to-sequence modeling, there are different pre-trained models, such as BART or MASS. These should be much more useful than BERT.
Update in September 2022: There are multilingual BERT-like models, the most famous are multilingual BERT and XLM-RoBERTa. When fine-tuned carefully, they can be used as a universal encoder for machine translation and enable so-called zero-shot machine translation. The model is trained to translate from several source languages into English, but in the end, it can translate from all languages covered by the multilingual BERT-like models. The method is called SixT.

Transforming h2o model into non-h2o one

I know that there is possibility to export/import h2o model, that was previously trained.
My question is - is there a way to transform h2o model to a non-h2o one (that just works in plain R)?
I mean that I don't want to launch the h2o environment (JVM) since I know that predicting on trained model is simply multiplying matrices, applying activation function etc.
Of course it would be possible to extract weights manually etc., but I want to know if there is any better way to do it.
I do not see any previous posts on SA about this problem.
No.
Remember that R is just the client, sending API calls: the algorithms (those matrix multiplications, etc.) are all implemented in Java.
What they do offer is a POJO, which is what you are asking for, but in Java. (POJO stands for Plain Old Java Object.) If you call h2o.download_pojo() on one of your models you will see it is quite straightforward. It may even be possible to write a script to convert it to R code? (Though it might be better, if you were going to go to that trouble, to convert it to C++ code, and then use Rcpp!)
Your other option is to export the weights and biases, in the case of deep learning, implement your own activation function, and use them directly.
But, personally, I've never found the Java side to be a bottleneck, either from the point of view of dev ops (install is easy) or computation (the Java code is well optimized).

How can I "think OOP" when using R?

I am a statistics graduate student who works a lot with R. I am familiar with OOP in other programming contexts. I even see its use in various statistical packages that define new classes for storing data.
At this stage in my graduate career, I am usually coding some algorithm for some class assignment--something that takes in raw data and gives some kind of output. I would like to make it easier to reuse code, and establish good coding habits, especially before I move on to more involved research. Please offer some advice on how to "think OOP" when doing statistical programming in R.
I would argue that you shouldn't. Try to think about R in terms of a workflow. There's some useful workflow suggestions on this page:
Workflow for statistical analysis and report writing
Another important consideration is line-by-line analysis vs. reproducible research. There's a good discussion here:
writing functions vs. line-by-line interpretation in an R workflow
Two aspects of OOP are data and the generics / methods that operate on data.
The data (especially the data that is the output of an analysis) often consists of structured and inter-related data frames or other objects, and one wishes to manage these in a coordinated fashion. Hence the OOP concept of classes, as a way to organize complex data.
Generics and the methods that implement them represent the common operations performed on data. Their utility comes when a collection of generics operate consistently across conceptually related classes. Perhaps a reasonable example is the output of lm / glm as classes, and the implementation of summary, anova, predict, residuals, etc. as generics and methods.
Many analyses follow familiar work flows; here one is a user of classes and methods, and gets the benefit of coordinated data + familiar generics. Thinking 'OOP' might lead you to explore the methods on the object, methods(class="lm") rather than its structure, and might help you to structure your work flows so they follow the well-defined channels of established classes and methods.
Implementing a novel statistical methodology, one might think about how to organize the results in to a coherent, inter-related data structure represented as a new class, and to write methods for the class that correspond to established methods on similar classes. Here one gets to represent the data internally in a way that is convenient for subsequent calculation rather than as a user might want to 'see' it (separating representation from interface). And it is easy for the user of your class (as Chambers says, frequently yourself) to use the new class in existing work flows.
It's a useful question to ask 'why OOP' before 'how OOP'.
You may want to check these links out: first one, second one.
And if you want to see some serious OO code in R, read manual page for ReferenceClasses (so called R5 object orientation), and take a look at Rook package, since it relies heavily on ReferenceClasses. BTW, Rook is a good example of reasonable usage of R5 in R coding. Previous experience with JAVA or C++ could be helpful, since R5 method dispatching differs from S3. Actually, S3 OO is very primitive, since the actuall "class" is saved as an object attribute, so you can change it quite easily.
S3: <method>.<class>(<object>)
R5: <object>$<method>
Anyway, if you can grab a copy, I recommend: "R in a Nutshell", chapter 10.
I have a limited knowledge of how to use R effectively, but there here is an article that allowed even me to walk through using R in an OO manner:
http://www.ibm.com/developerworks/linux/library/l-r3/index.html
I take exception to David Mertz's "The methods package is still somewhat tentative from what I can tell, but some moderately tweaked version of it seems certain to continue in later R versions" mentioned in the link in BiggsTRC answer. In my opinion, programming with classes and methods and using the methods package (S4) is the proper way to "think OOP" in R.
The last paragraph of chapter 9.2 "Programming with New Classes" (page 335) of John M. Chambers' "Software for Data Analysis" (2008) states:
"The amount of programming involved in using a new class may be much more than that involved in defining the class. You owe it to the users of your new classes to make that programming as effective as possible (even if you expect to be your own main user). So the fact that the programming style in this chapter and in Chapter 10 ["Methods and Generic Functions"] is somewhat different is not a coincidence. We're doing some more serious programming here."
Consider studying the methods package (S4).
Beyond some of the other good answers here (e.g. the R in a Nutshell chapter, etc), you should take a look at the core Bioconductor packages. BioC has always had a focus on strong OOP design using S4 classes.

What is a programming language which is appropriate with data classification project

I would like to easily implement a data classification project, so I'm looking for the language which provides the library for that. Could you suggest the proper language?
matlab is not exactly a programming language, but no doubt it's the easiest way to implementing math oriented programs. it has lots of toolboxes for classifications (e.g. MLP, SVM) optimization toolboxes.
There is a Python distribution called SciPy that has lots of tools for scientific programming and people have used it to do data classification. Some bioinformatics people have built Excel2SVM in Python.
If the focus of your work is on the data classification, not on developing software, then Python is a good choice because you can be more productive than with languages like java or C++.
I'd say you really need more information before choosing a language.
Where are you getting data from, what front end do you want to use (web / dedicated client) ?
C# could do just as good a job, or any Object oriented language.
Cheers
(A little late coming, but I thought this answer should be here for the record).
WEKA and MALLET are two useful libraries for data classification that I've come across. I've used WEKA in a couple of projects and can say that it is pretty mature. Both these libraries are Java-based.

Resources