Skip to content

Instantly share code, notes, and snippets.

View ines's full-sized avatar
🖤

Ines Montani ines

🖤
View GitHub Profile
@ines
ines / .zshrc
Last active February 28, 2021 19:42
Command to activate / create Python virtual environmment
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
@ines
ines / streamlit_prodigy.py
Created October 3, 2019 20:37
Streamlit + Prodigy
"""
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
@ines
ines / Install
Last active September 21, 2023 17:14
Streamlit + spaCy
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
@ines
ines / diff_strings.py
Created August 1, 2019 12:19
Print colored visual diff in Python
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":
@ines
ines / those_generously_buttered_noodles.py
Last active July 23, 2023 12:25
Using spaCy & NLP to create variations of "those generously buttered noodles"
# 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
@ines
ines / spacy_token_attrs.py
Last active May 2, 2021 04:32
spaCy v2.0 example: Get and set token text character spans as custom attribute extensions
# 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
@ines
ines / emoji.py
Last active March 19, 2017 12:44
Use emoji name for spaCy models in v1.7 🦄
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)
@ines
ines / _displacy.jade
Created October 20, 2016 12:48
displaCy.js NLP visualizer Jade/Pug mixin (to use in Node/Express, Harp, etc.)
//- 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