Package: weak-nlp
🔮 weak-nlpIntelligent information integration based on weak supervisionInstallationYou can set up this library via either running$ pip install weak-nlp, or via cloning this repository and running$ pip install -r requirements.txtin your repository.A sample installation would be:$ conda create --name weak-nlp python=3.9
$ conda activate weak-nlp
$ pip install weak-nlpUsageThe library consists of three main entities:Associations: an association contains the information of one record <> label mapping. This does not have to be ground truth label for a given record, but can also come from e.g. a labelfunction (see below for an example).Source vectors: A source vector combines the created associations from one logical source. Additionally, it marks whether the respective source vector can be seen as a reference vector, such as a manually labeled source vector containing thetruerecord <> label mappings.Noisy label matrices: Collection of source vectors that can be analyzed w.r.t. quality metrics (such as the confusion matrix, i.e., true positives etc.), quantity metrics (intersections and conflicts) or weakly supervisable labels.The following is an example for building a noisy label matrix for a classification taskimportweak_nlpdefcontains_keywords(text):ifany(termintextfortermin["val1","val2","val3"]):return"regular"texts=[...]lf_associations=[]fortext_id,textinenumerate(texts):label=contains_keywords(text)iflabelisnotNone:association=weak_nlp.ClassificationAssociation(text_id+1,label)lf_associations.append(association)lf_vector=weak_nlp.SourceVector(contains_keywords.__name__,False,lf_associations)ground_truths=[weak_nlp.ClassificationAssociation(1,"clickbait"),weak_nlp.ClassificationAssociation(2,"regular"),weak_nlp.ClassificationAssociation(3,"regular")]gt_vector=weak_nlp.SourceVector("ground_truths",True,ground_truths)cnlm=weak_nlp.CNLM([gt_vector,lf_vector])Whereas for extraction tasks, your code snippet could look as follows:importweak_nlpdefmatch_keywords(text):foridx,tokeninenumerate(text.split()):iftokenin["val1","val2","val3"]:yield"person",idx,idx+1# label, from_idx, to_idxtexts=[...]lf_associations=[]fortext_id,textinenumerate(texts):fortripletinmatch_keywords(text):label,from_idx,to_idx=tripletassociation=weak_nlp.ExtractionAssociation(text_id+1,label,from_idx,to_idx)lf_associations.append(association)lf_vector=weak_nlp.SourceVector(match_keywords.__name__,False,lf_associations)ground_truths=[weak_nlp.ExtractionAssociation(1,"person",1,2),weak_nlp.ExtractionAssociation(2,"person",4,5),]gt_vector=weak_nlp.SourceVector("ground_truths",True,ground_truths)enlm=weak_nlp.ENLM([gt_vector,lf_vector])RoadmapIf you want to have something added, feel free to open anissue.ContributingContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make aregreatly appreciated.If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!Fork the ProjectCreate your Feature Branch (git checkout -b feature/AmazingFeature)Commit your Changes (git commit -m 'Add some AmazingFeature')Push to the Branch (git push origin feature/AmazingFeature)Open a Pull RequestAnd please don't forget to leave a ⭐ if you like the work!LicenseDistributed under the Apache 2.0 License. See LICENSE.txt for more information.ContactThis library is developed and maintained bykern.ai. If you want to provide us with feedback or have some questions, don't hesitate to contact us. We're super happy to help ✌️