Slide 1

Slide 1 text

Do Angry People Have Poor Grammar? Ben Fields

Slide 2

Slide 2 text

An Exploration of Language Processing and Statistics in Python Ben Fields

Slide 3

Slide 3 text

intro and motivation

Slide 4

Slide 4 text

@alsothings - Do Angry People Have Poor Grammar? Have you ever noticed on social media

Slide 5

Slide 5 text

@alsothings - Do Angry People Have Poor Grammar? that the ‘loudest’

Slide 6

Slide 6 text

@alsothings - Do Angry People Have Poor Grammar? seem to not construct the best sentences?

Slide 7

Slide 7 text

@alsothings - Do Angry People Have Poor Grammar? me too.

Slide 8

Slide 8 text

@alsothings - Do Angry People Have Poor Grammar? But I am a skeptic

Slide 9

Slide 9 text

@alsothings - Do Angry People Have Poor Grammar? http://dx.doi.org/10.1037/1089-2680.2.2.175

Slide 10

Slide 10 text

@alsothings - Do Angry People Have Poor Grammar? So lets do some analysis

Slide 11

Slide 11 text

@alsothings - Do Angry People Have Poor Grammar? 1. Find pile of comments 2. Measure style and sentiment 3. ???? 4. Profit

Slide 12

Slide 12 text

@alsothings - Do Angry People Have Poor Grammar? 1. Find pile of comments 2. Measure style and sentiment 3. Statistical dependance? 4. Profit

Slide 13

Slide 13 text

@alsothings - Do Angry People Have Poor Grammar? 1. Find pile of comments 2. Measure style and sentiment 3. Statistical dependance? 4. more twitter followers

Slide 14

Slide 14 text

1. Find pile of comments

Slide 15

Slide 15 text

@alsothings - Do Angry People Have Poor Grammar? all of the reddit comments!

Slide 16

Slide 16 text

@alsothings - Do Angry People Have Poor Grammar? https://www.reddit.com/r/datasets/comments/3bxlg7/ i_have_every_publicly_available_reddit_comment

Slide 17

Slide 17 text

@alsothings - Do Angry People Have Poor Grammar? 1.7 Trillion reddit comments!

Slide 18

Slide 18 text

@alsothings - Do Angry People Have Poor Grammar? 59 Million reddit comments! https://mega.nz/#!ysBWXRqK!yPXLr25PgJi184pbJU3GtnqUY4wG7YvuPpxJjEmnb9A

Slide 19

Slide 19 text

@alsothings - Do Angry People Have Poor Grammar? (actually ~1% sample of that: 390k comments)

Slide 20

Slide 20 text

@alsothings - Do Angry People Have Poor Grammar? from nltk import tokenize … for comment in pile_of_comment: num_tokens = len(filter(lambda t:t not in punctuation, tokenize.word_tokenize(comment['body']))) if num_tokens < 5: continue

Slide 21

Slide 21 text

@alsothings - Do Angry People Have Poor Grammar? 319K comments from January 2015

Slide 22

Slide 22 text

2. Measure style and sentiment

Slide 23

Slide 23 text

@alsothings - Do Angry People Have Poor Grammar? grammar?

Slide 24

Slide 24 text

@alsothings - Do Angry People Have Poor Grammar? Context-Free Grammar! http://www.nltk.org/book/ch08.html

Slide 25

Slide 25 text

@alsothings - Do Angry People Have Poor Grammar? Great for analysing complex and ambiguous sentence structure http://www.nltk.org/book/ch08.html

Slide 26

Slide 26 text

@alsothings - Do Angry People Have Poor Grammar? http://www.imdb.com/title/tt0020640/

Slide 27

Slide 27 text

@alsothings - Do Angry People Have Poor Grammar? “One morning, I shot an elephant in my pyjamas. How he got in my pyjamas, I don't know.” http://www.nltk.org/book/ch08.html

Slide 28

Slide 28 text

@alsothings - Do Angry People Have Poor Grammar? “I shot an elephant in my pyjamas.” http://www.nltk.org/book/ch08.html

Slide 29

Slide 29 text

@alsothings - Do Angry People Have Poor Grammar? S -> NP VP PP -> P NP NP -> Det N | Det N PP | 'I' VP -> V NP | VP PP Det -> 'an' | 'my' N -> 'elephant' | 'pyjamas' V -> 'shot' P -> 'in' http://www.nltk.org/book/ch08.html

Slide 30

Slide 30 text

@alsothings - Do Angry People Have Poor Grammar? groucho_grammar = nltk.CFG.fromstring(from_last_slide) sent = ['I', 'shot', 'an', 'elephant', 'in', 'my', 'pyjamas'] parser = nltk.ChartParser(groucho_grammar) for tree in parser.parse(sent): print(tree) http://www.nltk.org/book/ch08.html

Slide 31

Slide 31 text

@alsothings - Do Angry People Have Poor Grammar? (S (NP I) (VP (VP (V shot) (NP (Det an) (N elephant))) (PP (P in) (NP (Det my) (N pyjamas))))) (S (NP I) (VP (V shot) (NP (Det an) (N elephant) (PP (P in) (NP (Det my) (N pajamas)))))) http://www.nltk.org/book/ch08.html

Slide 32

Slide 32 text

@alsothings - Do Angry People Have Poor Grammar? http://www.nltk.org/book/ch08.html S S NP VP NP VP VP PP V NP V NP P NP Det N Det N Det N PP P NP Det N I shot an elephant in my pyjamas I shot an elephant in my pyjamas

Slide 33

Slide 33 text

@alsothings - Do Angry People Have Poor Grammar? S -> NP VP PP -> P NP NP -> Det N | Det N PP | 'I' VP -> V NP | VP PP Det -> 'an' | 'my' N -> 'elephant' | 'pyjamas' V -> 'shot' P -> 'in' http://www.nltk.org/book/ch08.html

Slide 34

Slide 34 text

@alsothings - Do Angry People Have Poor Grammar? Extended ad nauseum: a definition of english

Slide 35

Slide 35 text

@alsothings - Do Angry People Have Poor Grammar? Extended ad nauseum: a static simplification of english

Slide 36

Slide 36 text

@alsothings - Do Angry People Have Poor Grammar? pCFG

Slide 37

Slide 37 text

@alsothings - Do Angry People Have Poor Grammar? probabilistic CFG

Slide 38

Slide 38 text

@alsothings - Do Angry People Have Poor Grammar? “The main problem is that there is no common agreement on what are grammatically correct (English) sentences; nor has anyone yet been able to offer a grammar precise enough to propose as definitive.” http://dl.acm.org/citation.cfm?id=1882777

Slide 39

Slide 39 text

@alsothings - Do Angry People Have Poor Grammar? Style checking!

Slide 40

Slide 40 text

@alsothings - Do Angry People Have Poor Grammar? lint for prose

Slide 41

Slide 41 text

@alsothings - Do Angry People Have Poor Grammar? proselint.com

Slide 42

Slide 42 text

@alsothings - Do Angry People Have Poor Grammar? proselint.com/write

Slide 43

Slide 43 text

@alsothings - Do Angry People Have Poor Grammar? https://github.com/amperser/proselint/ { "max_errors": 1000, "checks": { "butterick.symbols" : true, "carlin.filth" : true, "consistency.spacing" : true, "consistency.spelling" : true, "garner.airlinese" : true, … "inc.corporate_speak" : true, "leonard.exclamation" : true, "leonard.hell" : true, … "write_good.weasel_words" : true, "wsj.athletes" : true } }

Slide 44

Slide 44 text

@alsothings - Do Angry People Have Poor Grammar? https://github.com/amperser/proselint/ (from checks/leonard/exclamation.py) @memoize def check_repeated_exclamations(text): """Check the text.""" err = "leonard.exclamation.multiple" msg = u"Stop yelling. Keep your exclamation points under control." regex = r"[^A-Z]\b((\s[A-Z]+){3,})" return existence_check( text, [regex], err, msg, require_padding=False, ignore_case=False,max_errors=1, dotall=True)

Slide 45

Slide 45 text

@alsothings - Do Angry People Have Poor Grammar? mean std dev min 25% 50% 75% max lints 0.4298 1.0861 0 0 0 1 400 normed lints 0.0216 0.0497 0 0 0 0.0178 1.2

Slide 46

Slide 46 text

sentiment analysis http://www.nltk.org/howto/sentiment.html

Slide 47

Slide 47 text

@alsothings - Do Angry People Have Poor Grammar?

Slide 48

Slide 48 text

@alsothings - Do Angry People Have Poor Grammar? lul or luuuuuuuuuuuulz?

Slide 49

Slide 49 text

@alsothings - Do Angry People Have Poor Grammar? VADER (Valence Aware Dictionary for sEntiment Reasoning) http://comp.social.gatech.edu/papers/icwsm14.vader.hutto.pdf

Slide 50

Slide 50 text

@alsothings - Do Angry People Have Poor Grammar? Test Condition Example Text Baseline Yay. Another good phone interview. Punctuation1 Yay! Another good phone interview! Punctuation1 + Degree Mod. Yay! Another extremely good phone interview! Punctuation2 Yay!! Another good phone interview!! Capitalization YAY. Another GOOD phone interview. Punct1 + Cap. YAY! Another GOOD phone interview! Punct2 + Cap. YAY!! Another GOOD phone interview!! Punct3 + Cap. YAY!!! Another GOOD phone interview!!! Punct3 + Cap. + Degree Mod. YAY!!! Another EXTREMELY GOOD phone in- terview!!! Table 2: Example of baseline text with eight test conditions com- prised of grammatical and syntactical variations. post synt diffe 2. Mov from from tive the tenc 3. Tec leve prod (200 4. Opi http://comp.social.gatech.edu/papers/icwsm14.vader.hutto.pdf

Slide 51

Slide 51 text

@alsothings - Do Angry People Have Poor Grammar? mean std dev min 25% 50% 75% max positive 0.14381 0.15702 0 0 0.10800 0.22900 1 neutral 0.776917 0.175849 0 0.667000 0.789000 0.915000 1 0.079243 0.079243 0 0 0 0.128000 1

Slide 52

Slide 52 text

3. Statistical dependance?

Slide 53

Slide 53 text

@alsothings - Do Angry People Have Poor Grammar? y = f ( x )

Slide 54

Slide 54 text

@alsothings - Do Angry People Have Poor Grammar? regression! http://comp.social.gatech.edu/papers/icwsm14.vader.hutto.pdf

Slide 55

Slide 55 text

@alsothings - Do Angry People Have Poor Grammar?

Slide 56

Slide 56 text

@alsothings - Do Angry People Have Poor Grammar? http://comp.social.gatech.edu/papers/icwsm14.vader.hutto.pdf S = n X i=1 ri 2

Slide 57

Slide 57 text

@alsothings - Do Angry People Have Poor Grammar?

Slide 58

Slide 58 text

@alsothings - Do Angry People Have Poor Grammar? correlation testing

Slide 59

Slide 59 text

@alsothings - Do Angry People Have Poor Grammar? Pearson’s negative to correlation p lints 0.0311 4.535E-249 normed lints 0.0600 2.4228E-68

Slide 60

Slide 60 text

@alsothings - Do Angry People Have Poor Grammar? Nope.

Slide 61

Slide 61 text

@alsothings - Do Angry People Have Poor Grammar? NOPE.

Slide 62

Slide 62 text

conclusions!

Slide 63

Slide 63 text

@alsothings - Do Angry People Have Poor Grammar? People on reddit are generally reasonable,

Slide 64

Slide 64 text

@alsothings - Do Angry People Have Poor Grammar? but when they aren’t, the language isn’t any stylistically worse

Slide 65

Slide 65 text

@alsothings - Do Angry People Have Poor Grammar? at least last January.

Slide 66

Slide 66 text

Let’s have some questions !/alsothings