{"id":2857,"date":"2024-07-20T06:12:13","date_gmt":"2024-07-20T13:12:13","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=2857"},"modified":"2024-07-20T06:17:32","modified_gmt":"2024-07-20T13:17:32","slug":"438-large-language-model-llm-library-transformers-for-natural-language-processing-nlp-in-python","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2024\/07\/438-large-language-model-llm-library-transformers-for-natural-language-processing-nlp-in-python\/","title":{"rendered":"#438 Large language model (LLM) library Transformers for natural language processing (NLP) in python"},"content":{"rendered":"<p>Transformers<\/p>\n<p>One of the most prominent libraries for modern natural language processing (NLP) model frameworks, Transformers comes from the NLP powerhouse Hugging Face. The variety of pre-trained models available in Transformers is vast, with both foundational and fine-tuned models designed for tasks such as text classification, translation, question answering, and more.<\/p>\n<p>Key Features:<br \/>\nversatility (models exist for backends like PyTorch and TensorFlow), plentiful pre-trained models that can be customized, user-friendly APIs and docs, a robust user base to answer questions and help.<\/p>\n<p>Transformers is good for new users, as it is very simple to pick up the basics, but also useful enough to help with even the most complex of tasks. The library comes with extensive documentation, user-friendly APIs, and a nearly-unfathomable collection of available models. With Transformers, beginners can start using state-of-the-art models without a ton of deep learning knowledge.<\/p>\n<pre class=\"lang:python decode:true \" ># pip install transformers\n# Your currently installed version of Keras is Keras 3, but this is not\n# yet supported in Transformers. Please install the\n# backwards-compatible tf-keras package with\n# pip install tf-keras\n\nfrom transformers import pipeline\nclassifier = pipeline(\"sentiment-analysis\")\nresult = classifier(\"I like ice-cream.\")\nprint(result)\nresult = classifier(\"I don't like ice-cream.\")\nprint(result)\nresult = classifier(\"\u042f \u043b\u044e\u0431\u043b\u044e \u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u043e\u0435.\")\nprint(result)\nresult = classifier(\"\u042f \u043d\u0435 \u043b\u044e\u0431\u043b\u044e \u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u043e\u0435.\")\nprint(result)<\/pre>\n<p>Output:<\/p>\n<pre class=\"lang:python decode:true \" >All the weights of TFDistilBertForSequenceClassification were initialized from the PyTorch model.\nIf your task is similar to the task the model of the checkpoint was trained on, you can already use TFDistilBertForSequenceClassification for predictions without further training.\n[{'label': 'POSITIVE', 'score': 0.9990261793136597}]\n[{'label': 'NEGATIVE', 'score': 0.9980624318122864}]\n[{'label': 'POSITIVE', 'score': 0.5804928541183472}]\n[{'label': 'NEGATIVE', 'score': 0.770568311214447}]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Transformers One of the most prominent libraries for modern natural language processing (NLP) model frameworks, Transformers comes from the NLP powerhouse Hugging Face. The variety of pre-trained models available in Transformers is vast, with both foundational and fine-tuned models designed for tasks such as text classification, translation, question answering, and more. Key Features: versatility (models [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11,2],"tags":[130,131],"class_list":["post-2857","post","type-post","status-publish","format-standard","hentry","category-machine-learning","category-python","tag-llm","tag-transformers"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-K5","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1603,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/10\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-3-2-2-3-2-2-4-2-2\/","url_meta":{"origin":2857,"position":0},"title":"#307 Categorize support issues using multiclass classification with ML.NET using C#","author":"gantovnik","date":"2022-10-28","format":false,"excerpt":"Data file: Download the and place to Data folder two files: issues_train.tsv and the issues_test.tsv GitHubIssueData.cs Program.cs Output: https:\/\/github.com\/gantovnik\/wordpress_examples\/tree\/main\/ex307","rel":"","context":"In &quot;C#&quot;","block_context":{"text":"C#","link":"https:\/\/gantovnik.com\/bio-tips\/category\/c\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1827,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/04\/344-failsafe-topology-optimization\/","url_meta":{"origin":2857,"position":1},"title":"#344 Failsafe topology optimization","author":"gantovnik","date":"2023-04-20","format":false,"excerpt":"Failsafe topology optimization: FSO divides the structure into damage zones and generates multiple models (equal to the number of failure zones). Each model is the same as the original model minus one failure zone. In this process, the FSO method is applied by running Topology Optimization simultaneously for all such\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3616,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/08\/445-hypermesh-python-script-for-renumbering-the-elements-and-nodes\/","url_meta":{"origin":2857,"position":2},"title":"#445 HyperMesh python script for renumbering the elements and nodes","author":"gantovnik","date":"2024-08-13","format":false,"excerpt":"import hm import hm.entities as ent elems = hm.Collection(model,ent.Element) model.renumbersolverid(collection=elems,start_id=1,incr_val=1,offset_val=1,offset_flag=0,reserved_1=0,reserved_2=0,reserved_3=0) nodes = hm.Collection(model,ent.Node) model.renumbersolverid(collection=nodes,start_id=1000,incr_val=1,offset_val=1,offset_flag=0,reserved_1=0,reserved_2=0,reserved_3=0)","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1002,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/10\/180-linear-regression-using-python\/","url_meta":{"origin":2857,"position":3},"title":"#180 Linear regression using python","author":"gantovnik","date":"2021-10-26","format":false,"excerpt":"","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex180.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex180.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/10\/ex180.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1041,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/186-generate-the-feature-importance\/","url_meta":{"origin":2857,"position":4},"title":"#186 Generate the feature importance","author":"gantovnik","date":"2021-11-07","format":false,"excerpt":"","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/11\/ex186b.jpg?resize=1050%2C600&ssl=1 3x"},"classes":[]},{"id":1863,"url":"https:\/\/gantovnik.com\/bio-tips\/2023\/06\/350-optimization-with-gekko-in-python\/","url_meta":{"origin":2857,"position":5},"title":"#350 Optimization with GEKKO in Python","author":"gantovnik","date":"2023-06-27","format":false,"excerpt":"$latex max \\; 2x + 5y$ $latex s.t.$ $latex 5x + 3y \\le 10$ $latex 2x + 7y \\le 9$","rel":"","context":"In &quot;optimization&quot;","block_context":{"text":"optimization","link":"https:\/\/gantovnik.com\/bio-tips\/category\/optimization\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=2857"}],"version-history":[{"count":4,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2857\/revisions"}],"predecessor-version":[{"id":2862,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2857\/revisions\/2862"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=2857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=2857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=2857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}