text mining in r
play

Text Mining in R ( tm 101) ViennaR Mario Annau, - PowerPoint PPT Presentation

Text Mining in R ( tm 101) ViennaR Mario Annau, 22.2.2016 Textmining? Sta<s<cal analysis of textual data Use Cases include Spam Filtering


  1. Text ¡Mining ¡in ¡R ¡ ( tm ¡101) ¡ ViennaR ¡ Mario ¡Annau, ¡22.2.2016 ¡

  2. Textmining? ¡ • Sta<s<cal ¡analysis ¡of ¡textual ¡data ¡ • Use ¡Cases ¡include ¡ – Spam ¡Filtering ¡ – Search ¡ – Sen<ment ¡Analysis ¡ – Topic ¡Modelling ¡ – ... ¡

  3. tm? ¡ • Infrastructure ¡to ¡Analyze ¡Collec<ons ¡of ¡Texts ¡ (Corpora) ¡in ¡R ¡ • Typical ¡ tm ¡pipeline: ¡ 1. Read ¡Data ¡from ¡Numerous ¡Sources ¡into ¡Corpus ¡ 2. Preprocess ¡Data ¡ 3. Create ¡DTM/TDM ¡ 4. Apply ¡Model ¡

  4. Contents ¡ • Data ¡Reading ¡ • Data ¡Structures ¡ • Preprocessing ¡Pipeline ¡ removePunctua<on, ¡tolower, ¡removeWords, ¡ stripWhitespace, ¡stemDocument ¡ • Examples ¡ • Known ¡Weaknesses ¡and ¡Outlook ¡ • Plans ¡for ¡ Sen'mentAnalysis ¡ (tm.plugin.sen<ment ¡2.0) ¡

  5. Data ¡Reading ¡ • tm ¡ Separates ¡Data ¡ Source ¡and ¡ Reader ¡(Iterator) ¡ • Supported ¡ Data ¡Sources ¡and ¡Readers: ¡ ¡ ¡ R> tm::getSources() [1] "DataframeSource" "DirSource" "URISource" "VectorSource" [5] "XMLSource" "ZipSource" R> tm::getReaders() [1] "readDOC" "readPDF" [3] "readPlain" "readRCV1" [5] "readRCV1asPlain" "readReut21578XML" [7] "readReut21578XMLasPlain" "readTabular" [9] "readTagged" "readXML" • e.g. ¡Read ¡PDF ¡Files ¡from ¡Directory: ¡ ¡ R> Corpus(DirSource(directory = “.", pattern = "*.pdf"), readerControl = list(reader = readPDF, language = "en")) ¡

  6. Data ¡Structures ¡ • TextDocument ¡( NLP ) ¡ • Annota<ons ¡( NLP ) ¡ • Corpus ¡ • DocumentTermMatrix ¡

  7. Preprocessing ¡Pipeline ¡ R> removePunctuation ("This is awesome and cool!") [1] "This is awesome and cool" R> tolower ("This is awesome and cool!") [1] "this is awesome and cool!" R> removeWords ("This is awesome and cool!", stopwords()) [1] "This awesome cool!“ R> stripWhitespace (removeWords(tolower(removePunc tuation("This is awesome and cool!")), stopwords())) [1] " awesome cool“ R>stemDocument(crude[[1]])

  8. Document ¡Term ¡Matrix ¡ R> control = list( removePunctuation = TRUE, removeNumbers = TRUE, tolower = TRUE, removeWords = list(stopwords("english")), stripWhitespace = TRUE, stemDocument = TRUE) R> dtm <- DocumentTermMatrix(crude, control=control)

  9. Calculate ¡Simple ¡Sen<ment ¡Score ¡ • We ¡can ¡now ¡use ¡the ¡DTM ¡to ¡calculate ¡ sen<ment ¡scores ¡based ¡on ¡dic<onary ¡ • e.g. ¡ sentiment <- DocumentTermMatrix(crude, control=control) pos <- tm_term_score(dtm, dic_gi$positive, FUN = slam::row_sums) neg <- tm_term_score(dtm, dic_gi$negative, FUN = slam::row_sums) sentiment <- (pos - neg) / (pos + neg) ¡

  10. Known ¡Weaknesses ¡ • ? ¡

  11. Sen'mentAnalysis ¡ package ¡ • tm, ¡tm.plugin.sen'ment ¡-­‑> ¡bag ¡of ¡words ¡ approach ¡with ¡caveats ¡ • syuzhet ¡-­‑> ¡nice ¡collec<on ¡of ¡techniques, ¡quite ¡ different ¡goals ¡ • coreNLP ¡ • Datasets? ¡-­‑> ¡Bing ¡Liu ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend