This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function venv { | |
default_envdir=".env" | |
envdir=${1:-$default_envdir} | |
if [ ! -d $envdir ]; then | |
python -m venv $envdir | |
pip install ipython black flake8 | |
echo -e "\x1b[38;5;2m✔ Created virtualenv $envdir\x1b[0m" | |
fi | |
source $envdir/bin/activate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example of a Streamlit app for an interactive Prodigy dataset viewer that also lets you | |
run simple training experiments for NER and text classification. | |
Requires the Prodigy annotation tool to be installed: https://prodi.gy | |
See here for details on Streamlit: https://streamlit.io. | |
""" | |
import streamlit as st | |
from prodigy.components.db import connect | |
from prodigy.models.ner import EntityRecognizer, merge_spans, guess_batch_size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install streamlit | |
pip install spacy | |
python -m spacy download en_core_web_sm | |
python -m spacy download en_core_web_md | |
python -m spacy download de_core_news_sm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import difflib | |
import wasabi | |
def diff_strings(a, b): | |
output = [] | |
matcher = difflib.SequenceMatcher(None, a, b) | |
for opcode, a0, a1, b0, b1 in matcher.get_opcodes(): | |
if opcode == "equal": | |
output.append(a[a0:a1]) | |
elif opcode == "insert": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using spaCy & NLP to create variations of "those generously buttered noodles" | |
# See here: https://twitter.com/ArielDumas/status/1086294656957272065 | |
# | |
# Disclaimer 1: This is a quick, simplified example focusing on one particular | |
# sentence. There are obviously many more different constructions and | |
# different types of dependencies you want to cover. Some aspects also become | |
# significantly more difficult if you're working with, say, German instead of | |
# English. | |
# | |
# Disclaimer 2: Creating spam comments is a very bad use case for NLP and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
from __future__ import unicode_literals | |
from spacy.lang.en import English | |
from spacy.tokens import Token | |
# Example of using spaCy v2.0's custom attribute extensions to get and set | |
# character spans of a token text as token attributes. | |
# Discussion: https://twitter.com/DavidWell/status/920245066404450304 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import spacy | |
nlp = spacy.load('🦄') | |
doc = nlp(u'Wow, my model is named 🦄 !') | |
for word in doc: | |
print(word.text, word.tag_, word.dep_, word.head.text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//- Usage: +displacy({ arcs: [...], words: [...] }) | |
//- Blog post for more info: https://explosion.ai/blog/displacy-js-nlp-visualizer | |
//- spaCy REST service to generate JSON markup: https://github.com/explosion/spacy-services | |
- var distance = 200 | |
- var offsetX = 50 | |
- var arrowSpacing = 20 | |
- var arrowWidth = 10 | |
- var arrowStroke = 2 |