Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Mastering spaCy

You're reading from   Mastering spaCy Build structured NLP solutions with custom components and models powered by spacy-llm

Arrow left icon
Product type Paperback
Published in Feb 2025
Publisher Packt
ISBN-13 9781835880463
Length 238 pages
Edition 2nd Edition
Languages
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Déborah Mesquita Déborah Mesquita
Author Profile Icon Déborah Mesquita
Déborah Mesquita
Duygu Altınok Duygu Altınok
Author Profile Icon Duygu Altınok
Duygu Altınok
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Part 1: Getting Started with spaCy
2. Chapter 1: Getting Started with spaCy FREE CHAPTER 3. Chapter 2: Core Operations with spaCy 4. Part 2: Advanced Linguistic and Semantic Analysis
5. Chapter 3: Extracting Linguistic Features 6. Chapter 4: Mastering Rule-Based Matching 7. Chapter 5: Extracting Semantic Representations with spaCy Pipelines 8. Chapter 6: Utilizing spaCy with Transformers 9. Part 3: Customizing and Integrating NLP Workflows
10. Chapter 7: Enhancing NLP Tasks Using LLMs with spacy-llm 11. Chapter 8: Training an NER Component with Your Own Data 12. Chapter 9: Creating End-to-End spaCy Workflows with Weasel 13. Chapter 10: Training an Entity Linker Model with spaCy 14. Chapter 11: Integrating spaCy with Third-Party Libraries 15. Index 16. Other Books You May Enjoy

Training with a custom corpus reader

spaCy’s Corpus class manages annotated corpora for data loading during training. The default corpus reader (spacy.Corpus.v1) creates the Example objects using the make_doc() method of the Language class. This method only tokenizes the text. To train the EntityLinker component, it needs to have the entities available in the doc. That’s why we will create our own corpus reader in a file called custom_functions.py. The reader should receive as parameters the path to the DocBin file and the nlp object. Inside the method, we will loop through each Doc to create the examples. Let’s go ahead and create this method:

  1. First, we disable the EntityLinker component of the pipeline and then get all the docs from the DocBin file:
    def read_files(file: Path, nlp: "Language") -> Iterable[Example]:
       with nlp.select_pipes(disable="entity_linker"):
          doc_bin = DocBin...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime