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

text mining in r
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Text ¡Mining ¡in ¡R ¡

(tm ¡101) ¡

ViennaR ¡ Mario ¡Annau, ¡22.2.2016 ¡

slide-2
SLIDE 2

Textmining? ¡

  • Sta<s<cal ¡analysis ¡of ¡textual ¡data ¡
  • Use ¡Cases ¡include ¡

– Spam ¡Filtering ¡ – Search ¡ – Sen<ment ¡Analysis ¡ – Topic ¡Modelling ¡ – ... ¡

slide-3
SLIDE 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 ¡
slide-4
SLIDE 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) ¡
slide-5
SLIDE 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")) ¡

slide-6
SLIDE 6

Data ¡Structures ¡

  • TextDocument ¡(NLP) ¡
  • Annota<ons ¡(NLP) ¡
  • Corpus ¡
  • DocumentTermMatrix ¡
slide-7
SLIDE 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]])

slide-8
SLIDE 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)

slide-9
SLIDE 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)

¡

slide-10
SLIDE 10

Known ¡Weaknesses ¡

  • ? ¡
slide-11
SLIDE 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 ¡