Share
Embed
2021-02-01-rel_video
Creating a custom trainable component with spaCy: an example use-case for Relation Extraction
Slides to support this tutorial video: https://www.youtube.com/watch?v=8HL-Ap5_Axo
Sofie Van Landeghem
February 01, 2021
Transcript
67 slides
-
v3 So fi e Van Landeghem FOR NAMED ENTITY Trainable
Component Relation Extraction CUSTOM -
Models written in any framework Production-ready training system, model packaging
& workflow management spacy.io -
Models written in any framework Multi-task learning with transformers like
BERT Production-ready training system, model packaging & workflow management spacy.io -
Models written in any framework Multi-task learning with transformers like
BERT Production-ready training system, model packaging & workflow management Fully custom trainable pipeline components spacy.io -
Document Machine Learning model Predictions matrix Doc Text ner rel
step #1: implement model -
Document Machine Learning model Predictions matrix Doc Text ner rel
step #1: implement model step #2: implement pipeline component -
Document Machine Learning model Predictions matrix Doc Text ner rel
step #1: implement model step #3:enhance accuracy transformer step #2: implement pipeline component -
thinc.ai type-checked functional programming API for composing models wrap layers
defined in any framework -
Document GATA3 inhibits FOXP3 expression Tokens + NER [GATA3, inhibits,
FOXP3, expression] -
Document GATA3 inhibits FOXP3 expression Tokens + NER [GATA3, inhibits,
FOXP3, expression] Token vectors [[-0.42, 1.93, -1.08, 0.28, -0.71] [ 3.84, 2.59, -0.14, -3.77, -0.66] [ 3.35, -1.51, 1.23, -0.88, -2.19] [ 3.77, -2.17, -0.48, -1.73, 1.10]] -
Document GATA3 inhibits FOXP3 expression Tokens + NER [GATA3, inhibits,
FOXP3, expression] Token vectors [[-0.42, 1.93, -1.08, 0.28, -0.71] [ 3.84, 2.59, -0.14, -3.77, -0.66] [ 3.35, -1.51, 1.23, -0.88, -2.19] [ 3.77, -2.17, -0.48, -1.73, 1.10]] Instance 1 Instance 2 GATA3 -> FOXP3 [-0.42, 1.93, -1.08, 0.28, -0.71, 3.35, -1.51, 1.23, -0.88, -2.19] FOXP3 -> GATA3 [ 3.35, -1.51, 1.23, -0.88, -2.19, -0.42, 1.93, -1.08, 0.28, -0.71] -
[GATA3, inhibits, FOXP3, expression] Instance data [[-0.42, 1.93, -1.08, 0.28,
-0.71, 3.35, -1.51, 1.23, -0.88, -2.19] [ 3.35, -1.51, 1.23, -0.88, -2.19, -0.42, 1.93, -1.08, 0.28, -0.71]] -
[GATA3, inhibits, FOXP3, expression] Instance data [[-0.42, 1.93, -1.08, 0.28,
-0.71, 3.35, -1.51, 1.23, -0.88, -2.19] [ 3.35, -1.51, 1.23, -0.88, -2.19, -0.42, 1.93, -1.08, 0.28, -0.71]] Classi fi cation layer Relation types: BINDING ACTIVATION INHIBITION -
[GATA3, inhibits, FOXP3, expression] Instance data [[-0.42, 1.93, -1.08, 0.28,
-0.71, 3.35, -1.51, 1.23, -0.88, -2.19] [ 3.35, -1.51, 1.23, -0.88, -2.19, -0.42, 1.93, -1.08, 0.28, -0.71]] Classi fi cation layer Relation types: BINDING ACTIVATION INHIBITION Predictions [[ 0.09, 0.14, 0.93 ] [ 0.11, 0.15, 0.31 ]] BINDING ACTIVATION INHIBITION -
[GATA3, inhibits, FOXP3, expression] Instance data [[-0.42, 1.93, -1.08, 0.28,
-0.71, 3.35, -1.51, 1.23, -0.88, -2.19] [ 3.35, -1.51, 1.23, -0.88, -2.19, -0.42, 1.93, -1.08, 0.28, -0.71]] Classi fi cation layer Relation types: BINDING ACTIVATION INHIBITION GATA3 -> FOXP3 BINDING: False, ACTIVATION: False, INHIBITION: True Instance 1 Instance 2 FOXP3 -> GATA3 BINDING: False, ACTIVATION: False, INHIBITION: False Predictions [[ 0.09, 0.14, 0.93 ] [ 0.11, 0.15, 0.31 ]] BINDING ACTIVATION INHIBITION -
Documents List[Doc] Token vectors List[Floats2d] tok2vec Entity vectors List[Floats2d] pooling
Candidate instances List[Tuple[Span, Span]] get_instances -
create_instance_tensor Instance tensor Floats2d Documents List[Doc] Token vectors List[Floats2d] tok2vec
Entity vectors List[Floats2d] pooling Candidate instances List[Tuple[Span, Span]] get_instances -
create_instance_tensor Instance tensor Floats2d Documents List[Doc] Predictions matrix Floats2d classification
layer Token vectors List[Floats2d] tok2vec Entity vectors List[Floats2d] pooling Candidate instances List[Tuple[Span, Span]] get_instances -
Document TGF-beta signalling induces Id2 Tokens + NER [TGF, -,
beta, signalling, induces, Id2] -
Document TGF-beta signalling induces Id2 Tokens + NER [TGF, -,
beta, signalling, induces, Id2] Token vectors [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-1.27, 2.21, -0.75, 1.07, -0.48] [-1.03, 0.94, 1.64, -0.05, -0.98] [-0.81, 0.72, -0.52, 0.67, -0.16]] -
Document TGF-beta signalling induces Id2 Tokens + NER [TGF, -,
beta, signalling, induces, Id2] Token vectors [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-1.27, 2.21, -0.75, 1.07, -0.48] [-1.03, 0.94, 1.64, -0.05, -0.98] [-0.81, 0.72, -0.52, 0.67, -0.16]] Entities Ragged [3, 1, 1, 3] Lengths Data [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16] [ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74]] -
Document TGF-beta signalling induces Id2 Tokens + NER [TGF, -,
beta, signalling, induces, Id2] Token vectors [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-1.27, 2.21, -0.75, 1.07, -0.48] [-1.03, 0.94, 1.64, -0.05, -0.98] [-0.81, 0.72, -0.52, 0.67, -0.16]] Entities Ragged [3, 1, 1, 3] Lengths Data [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16] [ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74]] Instance 1 Instance 2 -
[TGF, -, beta, signalling, induces, Id2] Entities Ragged [3, 1,
1, 3] Lengths Data [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16] [ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74]] -
[TGF, -, beta, signalling, induces, Id2] Entities Ragged [3, 1,
1, 3] Lengths Data [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16] [ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74]] Pooled entities Floats2d [[-0.60, 0.11, -0.37, 0.17, 0.17] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.60, 0.11, -0.37, 0.17, 0.17]] Instance 1 Instance 2 -
[TGF, -, beta, signalling, induces, Id2] Entities Ragged [3, 1,
1, 3] Lengths Data [[ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16] [ 1.22, -3.12, -0.19, 0.51, -0.46] [-1.71, 0.92, -0.67, 0.86, 2.70] [-1.32, 2.52, -0.26, -0.86, -1.74]] Instance tensor Floats2d [[-0.60, 0.11, -0.37, 0.17, 0.17, -0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16, -0.60, 0.11, -0.37, 0.17, 0.17]] Pooled entities Floats2d [[-0.60, 0.11, -0.37, 0.17, 0.17] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.81, 0.72, -0.52, 0.67, -0.16] [-0.60, 0.11, -0.37, 0.17, 0.17]] Instance 1 Instance 2 -
optimize model settings for accuracy or efficiency components to train
spacy.io/usage/training generate starter config -
con fi g.cfg structured section defining components factory function used
to create component -
con fi g.cfg structured section defining components factory function used
to create component registered function to create model architecture -
con fi g.cfg structured section defining components factory function used
to create component registered function to create model architecture function arguments -
con fi g.cfg custom factory sublayers model architecture listener layer
to connect to tok2vec component -
listener layer to connect to transformer component con fi g.cfg
spacy.io/usage/embeddings-transformers -
spacy.io/usage/v3 @spacy_io documentation and quickstart install spaCy v3 clone the
project template @OxyKodit -
spacy.io/usage/v3 @spacy_io documentation and quickstart install spaCy v3 thank you!
— clone the project template @OxyKodit