Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cyclecycle/role-pattern-nlp
Build and match patterns for semantic role labelling / information extraction with SpaCy
https://github.com/cyclecycle/role-pattern-nlp
nlp python semantic-role-labeling spacy
Last synced: 24 days ago
JSON representation
Build and match patterns for semantic role labelling / information extraction with SpaCy
- Host: GitHub
- URL: https://github.com/cyclecycle/role-pattern-nlp
- Owner: cyclecycle
- License: mit
- Created: 2019-05-22T05:56:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T05:47:08.000Z (almost 2 years ago)
- Last Synced: 2024-09-29T13:01:17.941Z (about 1 month ago)
- Topics: nlp, python, semantic-role-labeling, spacy
- Language: Python
- Homepage:
- Size: 5.16 MB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
d# Role Pattern
Build and match linguistic patterns for role labelling. Provides an example-driven approach to generate and refine patterns.
Uses graph-based pattern matching, built on SpaCy.
## Installation
With pip:
```
pip install role-pattern-nlp
```## Example usage
```python
# First, parse a string to create a SpaCy Doc object
import en_core_web_sm
text = "Forging involves the shaping of metal using localized compressive forces."
nlp = en_core_web_sm.load()
doc = nlp(text)from role_pattern_nlp import RolePatternBuilder
# Provide an example by mapping role labels to tokens
match_example = {
'arg1': [doc[0]], # [Forging]
'pred': [doc[1]], # [involves]
'arg2': [doc[3]], # [shaping]
}''' Create a dictionary of all the features we want the RolePatternBuilder to have access to
when building and refining patterns '''
feature_dict = {'DEP': 'dep_', 'TAG': 'tag_'}# Instantiate the pattern builder
role_pattern_builder = RolePatternBuilder(feature_dict)# Build a pattern. It will use all the features in the feature_dict by default
role_pattern = role_pattern_builder.build(match_example)# Match against any doc with the role_pattern
matches = role_pattern.match(doc)
print(matches)
'''
[{'arg1': [Forging], 'arg2': [shaping], 'pred': [involves]}]
'''
```See examples/ for demonstration as to how to refine a pattern using negative examples.
## API
### RolePattern
#### RolePattern.spacy_dep_pattern
The dependency pattern in the form used to create the SpaCy DependencyMatcher object.
#### RolePattern.token_labels
The list of labels that corresponds to the tokens matched by the pattern.
## Built with
- [SpaCy](https://spacy.io) - DependencyMatcher
- [SpaCy pattern builder](https://github.com/cyclecycle/spacy-pattern-builder)
- [networkx](https://github.com/networkx/networkx) - Used by SpaCy pattern builder