Skip to content

Instantly share code, notes, and snippets.

View UrszulaCzerwinska's full-sized avatar
:octocat:
exploring

Urszula Czerwinska UrszulaCzerwinska

:octocat:
exploring
View GitHub Profile
import spacy
from spacy import displacy
# install spacy model
#! pip install https://github.com/explosion/spacy-models/releases/download/en_core_web_md-2.2.0/en_core_web_md-2.2.0.tar.gz
nlp = spacy.load("en_core_web_md")
doc = nlp("I think Barack Obama met founder of Facebook at occasion of a release of a new NLP algorithm.")
displacy.render(doc, style="dep") # (1)
displacy.render(doc, style="ent") # (2)
@UrszulaCzerwinska
UrszulaCzerwinska / scrappingMedium.py
Last active October 29, 2019 13:09
scrapping medium
# import custom modules
import html_file_parsing as hfp
# define listing sources
Tech_Topics=[
'https://medium.com/topic/artificial-intelligence',
'https://medium.com/topic/blockchain',
'https://medium.com/topic/cryptocurrency',
'https://medium.com/topic/data-science',
'https://medium.com/topic/machine-learning',
@UrszulaCzerwinska
UrszulaCzerwinska / html_file_parsing.py
Created October 29, 2019 13:11
functions for medium scrapping
#import libraries
from bs4 import BeautifulSoup
import requests
import re
import pandas as pd
import json
class ArticleTable(object):
"""From medium page with listing of articles get links and then extract info from each article"""
from __future__ import unicode_literals, print_function
import re
import spacy
import pandas as pd
from spacy import displacy
import os
from collections import defaultdict
import itertools
import plac
import random
from evalmodel import test_eval_model
dico, df_metrics = test_eval_model("ner_models/mytrainedmodel", TEST_DATA)
import re
from collections import Counter
import spacy
from graph_show import GraphShow
import itertools
from collections import defaultdict
class NewsMining():
class GraphShow():
""""Create demo page"""
def __init__(self):
self.base = '''
<html>
<head>
<script type="text/javascript" src="VIS/dist/vis.js"></script>
<link href="VIS/dist/vis.css" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
#ipmort finction from other gists
from entites_graph import NewsMining
from html_file_parsing import ArticleParsing
#imports
import pandas as pd
# set url
url = "https://towardsdatascience.com/cat-dog-or-elon-musk-145658489730"
import plotly.io as pio
pio.templates.default = "plotly_white"
from plotly.subplots import make_subplots
import pandas as pd
import plotly.express as px
import matplotlib.pylab as pl
import numpy as np
def interaction_plot(col1, col2, interaction_values, background_display, is_cat=True, width=700, height=500,opacity=0.7):
"""
This function plots shap interaction values between two selected columns (col1 & col2), where x axis are values of column 1, y axis are shap interaction values, and hue (color) is the second column.
Args:
col1 (str) : name of the first feature
col2 (str) : name of the second feature
interaction_values (numpy.array) : matrix obtained with shap shap_interaction_values
background_display (pandas.DataFrame) : the original values for background data used in shap explainer
is_cat (bool) : is the col2 a categorical value, True by default