| 1 | = Stylometry = |
| 2 | |
| 3 | [[https://is.muni.cz/auth/predmet/fi/ia161|IA161]] [[en/AdvancedNlpCourse|Advanced NLP Course]], Course Guarantee: Aleš Horák |
| 4 | |
| 5 | Prepared by: Honza Rygl |
| 6 | |
| 7 | == State of the Art == |
| 8 | |
| 9 | The analysis of author's characteristic |
| 10 | writing style and vocabulary has been used to uncover author's traits such as authorship, age, or gender |
| 11 | documents by both manual linguistic approaches and automatic algorithmic methods. |
| 12 | |
| 13 | The most common approach to stylometry problems |
| 14 | is to combine stylistic analysis with machine learning techniques: |
| 15 | 1. specific style markers are extracted, |
| 16 | 2. a classification procedure is applied to extracted markers |
| 17 | |
| 18 | |
| 19 | === References === |
| 20 | |
| 21 | 1. Stamatatos, E. (2009), A Survey of Modern Authorship Attribution Methods (2009), Journal of the American Society for Information Science and Technology, 60(3), 538-556. [[http://www.clips.ua.ac.be/~walter/educational/material/Stamatatos_survey2009.pdf | pdf]] |
| 22 | 2. Kestemont, M. (2014), Function Words in Authorship Attribution From Black Magic to Theory? Proceedings of the 3rd Workshop on Computational Linguistics for Literature, EACL 2014, 59–66 [[http://aclweb.org/anthology/W14-0908 | pdf]] |
| 23 | 1. Walter, D. Explanation in Computational Stylometry |
| 24 | |
| 25 | == Practical Session == |
| 26 | |
| 27 | Student will get to know a *Style & Identity Recognition* tool. They will test this tool on prepared data. |
| 28 | Their goal will be to implement a small function to extract style markers from a text. |
| 29 | |
| 30 | 1. go to `asteria04.fi.muni.cz` server: |
| 31 | {{{ |
| 32 | ssh asteria04.fi.muni.cz |
| 33 | }}} |
| 34 | 2. Download a [[htdocs:bigdata/stylometry-assignment.zip|python package with the assignment]] |
| 35 | {{{ |
| 36 | wget https://nlp.fi.muni.cz/trac/research/chrome/site/bigdata/stylometry-assignment.zip |
| 37 | }}} |
| 38 | 3. Unzip the downloaded file |
| 39 | {{{ |
| 40 | unzip stylometry-assignment.zip |
| 41 | }}} |
| 42 | 4. Go to the unziped folder |
| 43 | {{{ |
| 44 | cd sir-assignment |
| 45 | }}} |
| 46 | 5. Test the prepared program that analyses data from on-line dating services to distinguish gender (masculine/feminine) by text style features |
| 47 | {{{ |
| 48 | ./run.sh |
| 49 | }}} |
| 50 | |
| 51 | `run.sh` can have two optional parameters: |
| 52 | {{{ |
| 53 | ./run.sh [number_of_testing_cycles] [show_first_N_erroneously_predicted_documents] |
| 54 | }}} |
| 55 | The default values, i.e. running `./run.sh` without parameters, are `100` cycles and `no documents` (`./run.sh 100 0`). For faster feature testing even `./run.sh 10` should be sufficient. |
| 56 | |
| 57 | Example with document output: |
| 58 | {{{ |
| 59 | [xrygl@asteria04:~/temp/sir-assignment]$ ./run.sh 10 1 |
| 60 | author: on |
| 61 | text: Ahoj, (nejen) pro výlety do víru podivnězimního velkoměsta, či divočiny |
| 62 | venkova, hledá se partnerka přiměřených rozměrů, tvarů a úrovně. Slečny veselé |
| 63 | povahy preferovány; ona je to nejspíš nutnost :-) |
| 64 | morphology: ((u'<s>', u'<s>'), (u'Ahoj', u'N.N.I.S.1.-.-.-.-.-.A.-.-.-.-'), |
| 65 | (u',', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), (u'(', |
| 66 | u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), (u'nejen', u'T.T.-.-.-.-.-.-.-.-.-.-.-.-.-'), |
| 67 | (u')', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), (u'pro', |
| 68 | u'R.R.-.-.4.-.-.-.-.-.-.-.-.-.-'), (u'v\xfdlety', |
| 69 | u'N.N.I.P.4.-.-.-.-.-.A.-.-.-.-'), (u'do', u'R.R.-.-.2.-.-.-.-.-.-.-.-.-.-'), |
| 70 | (u'v\xedru', u'N.N.I.S.2.-.-.-.-.-.A.-.-.-.-'), (u'podivn\u011bzimn\xedho', |
| 71 | u'A.A.N.S.2.-.-.-.-.1.A.-.-.-.-'), (u'velkom\u011bsta', |
| 72 | u'N.N.N.S.2.-.-.-.-.-.A.-.-.-.-'), (u',', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), |
| 73 | (u'\u010di', u'J.^.-.-.-.-.-.-.-.-.-.-.-.-.-'), (u'divo\u010diny', |
| 74 | u'N.N.F.S.2.-.-.-.-.-.A.-.-.-.-'), (u'venkova', |
| 75 | u'N.N.I.S.2.-.-.-.-.-.A.-.-.-.-'), (u',', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), |
| 76 | (u'hled\xe1', u'V.B.-.S.-.-.-.3.P.-.A.A.-.-.-'), (u'se', |
| 77 | u'P.7.-.X.4.-.-.-.-.-.-.-.-.-.-'), (u'partnerka', |
| 78 | u'N.N.F.S.1.-.-.-.-.-.A.-.-.-.-'), (u'p\u0159im\u011b\u0159en\xfdch', |
| 79 | u'A.A.I.P.2.-.-.-.-.1.A.-.-.-.-'), (u'rozm\u011br\u016f', |
| 80 | u'N.N.I.P.2.-.-.-.-.-.A.-.-.-.-'), (u',', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), |
| 81 | (u'tvar\u016f', u'N.N.I.P.2.-.-.-.-.-.A.-.-.-.-'), (u'a', |
| 82 | u'J.^.-.-.-.-.-.-.-.-.-.-.-.-.-'), (u'\xfarovn\u011b', |
| 83 | u'N.N.F.S.2.-.-.-.-.-.A.-.-.-.-'), (u'.', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), |
| 84 | (u'<s>', u'<s>'), (u'Sle\u010dny', u'N.N.F.P.1.-.-.-.-.-.A.-.-.-.-'), |
| 85 | (u'vesel\xe9', u'A.A.N.S.1.-.-.-.-.1.A.-.-.-.-'), (u'povahy', |
| 86 | u'N.N.F.S.2.-.-.-.-.-.A.-.-.-.-'), (u'preferov\xe1ny', |
| 87 | u'V.s.T.P.-.-.-.X.X.-.A.P.-.-.-'), (u';', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), |
| 88 | (u'ona', u'P.P.F.S.1.-.-.3.-.-.-.-.-.-.-'), (u'je', |
| 89 | u'V.B.-.S.-.-.-.3.P.-.A.A.-.-.-'), (u'to', u'P.D.N.S.1.-.-.-.-.-.-.-.-.-.-'), |
| 90 | (u'nejsp\xed\u0161', u'D.g.-.-.-.-.-.-.-.3.A.-.-.-.-'), (u'nutnost', |
| 91 | u'N.N.F.S.1.-.-.-.-.-.A.-.-.-.-'), (u':', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), |
| 92 | (u'-', u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-'), (u')', |
| 93 | u'Z.:.-.-.-.-.-.-.-.-.-.-.-.-.-')) |
| 94 | Acc: 73.7 +- 2.2% (baseline 50.0%, 10 iterations) |
| 95 | }}} |
| 96 | |
| 97 | === Task === |
| 98 | Examine files in `stylometry_features` folder. |
| 99 | Modify the `assignment.py` file to increase the accuracy of methods (use `vi` or `nano` command for editing). |
| 100 | You can create another classes inside, change their names and class names to improve the accuracy score. Don't forget to add new classes into the `assignments` list in this file. |
| 101 | |
| 102 | Suggestions for your inspiration include: |
| 103 | * diacritics usage (yes/no), a regular expression will be needed |
| 104 | * sentence endings (number of sentences, or typical endings) |
| 105 | * repetitions of words in sentences/in the text |
| 106 | * usage of uppercase letters |
| 107 | * length of sentences/text |
| 108 | * POS tags (n-grams) |
| 109 | * word n-grams |
| 110 | * character n-grams |
| 111 | |
| 112 | Each modification can be tested by running `./run.sh` again. |
| 113 | The first call of `run.sh` can be slower, because documents are morphologically analysed during the first run. |
| 114 | |
| 115 | Submit your assignment file. Write nice Python code and don't forget about PEP8 (https://www.python.org/dev/peps/pep-0008/). |