Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Word Embedding: come codificare il linguaggio n...

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →
Avatar for aianni aianni
April 08, 2017

Word Embedding: come codificare il linguaggio naturale per algoritmi di previsione e classificazione

Da qualche anno si parla sempre più insistentemente di Word Embedding, identificando così quell’insieme di tecniche che tentano di modellare il linguaggio umano creando una mappatura delle parole nel campo vettoriale. Come spesso accade per ambiti in rapido sviluppo, si è assistito alla nascita di diversi approcci algoritmici tra i quali a volte è difficile districarsi. Da questo punto di vista un linguaggio di propotipazione rapida come Python consente l’implementazione e l’utilizzo di una serie di librerie al fine di scegliere di volta in volta quelle che meglio modellano il problema in esame. Il talk mostra la potenzialità del word embedding entrando nel merito di due applicazioni reali relative a due contesti lontani fra loro, quali quelli della pubblica amministrazione e del privato. In ambito PA viene mostrato come, analizzando le descrizioni progettuali presentate da un insieme di aziende ad un importante istituto italiano, è possibile prevedere l’esito delle rispettive richieste di finanziamento, consentendo di aumentare in modo sostanziale il numero degli investimenti. Nella seconda parte ci spostiamo invece nel privato e mostriamo come codificare un’informazione naturalmente non strutturata, come la descrizione di un intervento in una officina meccanica, rendendola così gestibile al pari di quella strutturata.
A.Ianni, F.Tuosto

Avatar for aianni

aianni

April 08, 2017

Other Decks in Technology

Transcript

  1. Algorithms Applications SOM Filtered applications COMING BACK TO THE BUSINESS

    UNDERSTANDING MDS Network Analysis ? Application description Category
  2. CONSIDERING THE UNSTRUCTURED DATA: a first try (vector space model)…

    Term 1 Term 2 Term 3 … … Term − 2 Term − 1 Term Project description 1 0.15 0.32 0.00 … … 0.33 0.84 0.01 … … … … … … … … … Project description 0.41 0.54 0.00 … … 0.04 0.00 0.02 Term frequency-inverse document frequency (tf-idf) Application description Category , = , × log “The fact that, for example, not every adjectives occurs with every noun can be used as a measure of meaning difference… In other words, difference in meaning correlates with difference in distribution.” Harris (1954)
  3. WORD EMBEDDING «… how can we learn a model that

    embeds each word in a vector space and the vector says something interesting…» Cool guy knowledge Features: 1 , 2 , … , ( ) (1 ) … (2 ) Contextual information alone constitutes a viable representation of linguistic items (contextualism). 1) Direct : words similarity 2) Indirect : NLP tasks (classification, clustering, named entity recognition, sentiment analysis, …) «Undoubltedly PyCON is the best conference focused on the python language and the most amazing thing ever...!» WHAT WHY HOW
  4. Annual Meetings of the Association for Computational Linguistics (ACL) Conferences

    on Empirical Methods in Natural Language Processing (EMNLP) WORD EMBEDDING a quick market research Year # ‘word embedding’ 2013 0 2014 4 2015 12 2016 17 Year # ‘embedding’ 2013 2 2014 8 2015 25 2016 20
  5. “You shall know a word by the company it keeps”

    (Firth, J. R. 1957:11) “… linguistics was the study of “processes and patterns of life”; “The essential social basis for the study of meaning of texts is the context of situation” (1956) “… language is to be regarded as “embedded in the matrix of living experience…” (1968) “… meaning “is deeply embedded in the living processes of persons maintaining themselves in society” (1968) WORD EMBEDDING: the importance of the context Distributional hypothesis (Harris, 1954): “… you can determine the meaning of a word by looking at its company (its context). If two words occur in a same position in two sentences, they are very much related either in semantics or syntactics.” Zellig Harris “… the complete meaning of a word is always contextual, and no study of meaning apart from context can be taken seriously” (1935)
  6. Word2Vec A two-layer neural net that processes text. Its input

    is a text corpus and its output is a set of vectors: feature vectors for words in that corpus. C-BOW: Predicting the word given its context Skip-gram: Predicting the context given a word 1 , 2 , … , max ∈ ∈() (|; ) argmax (,)∈ log (|; ) ; = ∙ ′∈ ′∙
  7. WORD EMBEDDING meaningful vectors but… watch the biases R King

    Woman 0.99 0.99 0.05 0.7 0.02 0.01 0.999 0.5 royality masculinity femminility age
  8. WORD EMBEDDING Coming back to the project… words embedding «Da

    questo punto di vista un linguaggio di propotipazione rapida come Python consente l’implementazione e l’utilizzo di una serie di librerie al fine di scegliere di volta in volta quelle che meglio modellano il problema in esame.» Application description embedding ?
  9. WORD EMBEDDING Does it really work…? Word Embedding for Natural

    Language Processing in Python: Word embeddings are a family of Natural Language Processing (NLP) algorithms where words are mapped to vectors in low-dimensional space. The interest around word embeddings has been on the rise in the past few years because these techniques have been driving important improvements in many NLP applications like text classification sentiment analysis or machine translation. M.Bonzanini Word Embedding: come codificare il linguaggio naturale per algoritmi di previsione e classificazione Da qualche anno si parla sempre più insistentemente di Word Embedding identificando così quell insieme di tecniche che tentano di modellare il linguaggio umano creando una mappatura delle parole nel campo vettoriale. Come spesso accade per ambiti in rapido sviluppo si è assistito alla nascita di diversi approcci algoritmici tra i quali a volte è difficile districarsi. Da questo punto di vista un linguaggio di propotipazione rapida come Python consente l implementazione e l utilizzo di una serie di librerie al fine di scegliere di volta in volta quelle che meglio modellano il problema in esame. Il talk mostra la potenzialità del word embedding entrando nel merito di due applicazioni reali relative a due contesti lontani fra loro quali quelli della pubblica amministrazione e del privato. In ambito PA viene mostrato come analizzando le descrizioni progettuali presentate da un insieme di aziende ad un importante istituto italiano è possibile prevedere l esito delle rispettive richieste di finanziamento consentendo di aumentare in modo sostanziale il numero degli investimenti. Nella seconda parte ci spostiamo invece nel privato e mostriamo come codificare un informazione naturalmente non strutturata come la descrizione di un intervento in una officina meccanica rendendola così gestibile al pari di quella strutturata. A.Ianni, F.Tuosto
  10. Textual content Distribuzione dei topics TF-IDF matrix word2vec matrix Cleaning

    & Transformation Vocabulary codification Wikipedia REJECTED Classification doc2vec matrix SUCCESSFUL RETREATED FORECASTING Structured content company data application data
  11. Ingestion and preprocessing Analytics Web Service Web services provide analytics

    services wrritten in: • Azure Machine Learning algorithms • Custom R algorithms integrated in AzureML • Custom python algorithms integrated in AzureML ARCHITECTURE
  12. HANDS ON CODE stealing from pycon.. from bs4 import BeautifulSoup

    import requests import re import csv USE_PROXY = True YEAR = 2017 MinNumberOfWords = 20 html_file = 'pyconSchedule_'+str(YEAR)+'.html' speech_file = 'speechText_'+str(YEAR)+'.csv' with open(html_file, 'r') as htmlFile, open('proxy_credentials.txt', 'r') as credentials, open(speech_file, 'w') as outputFile: lines = credentials.readlines() user = lines[0].split(":")[1] password = lines[1].split(":")[1] outputWriter = csv.writer(outputFile, delimiter=";", quoting=csv.QUOTE_NONE, quotechar='$', lineterminator='\n') if USE_PROXY: proxies={ 'http' : lines[0], 'https': lines[1] } else: proxies = { 'http' : None, 'https': None } html_doc= htmlFile.read() soup = BeautifulSoup(html_doc, 'html.parser') evts=soup.select('div.track > div') for evt in evts: # find the title title_html= evt.select('h3 > a') link='' if title_html: link=title_html[0].attrs['href'] if 'talks' in link: title_text=title_html[0].get_text() response=requests.get(link, proxies=proxies) description_content=response.content description_as_tag=BeautifulSoup(description_content,'html.parser') select = description_as_tag.select('div.cms') if select: tags=description_as_tag.select('span.tag') tags_list=[] if tags: for tag in tags: tags_list.append(tag.get_text().encode('utf8')) description_text= select[0].get_text() description_text=re.sub('[,:;\n\r()\!\?"]',' ',description_text) myLine = ['"'+title_text.encode('utf8')+'"','"'+description_text.encode('utf8')+'"',','.join( tags_list)] if len(myLine[0]) > MinNumberOfWords: outputWriter.writerow(myLine)