Difference between revisions of "Ltarlin1/Final Project"
(→Users) |
|||
| Line 12: | Line 12: | ||
As discussed in the above section, the tikz-dependency package uses the tikz interface to facilitate the graph-making process. The syntax of a dependency in this format is strikingly similar to that which we saw in class (i.e. #4->6) because both refer to the "from word" and the "to word" using offset from the beginning of the sentence, so it was relatively simple to translate from one form to another. | As discussed in the above section, the tikz-dependency package uses the tikz interface to facilitate the graph-making process. The syntax of a dependency in this format is strikingly similar to that which we saw in class (i.e. #4->6) because both refer to the "from word" and the "to word" using offset from the beginning of the sentence, so it was relatively simple to translate from one form to another. | ||
| − | == | + | == Who Will Benefit == |
This tool would be useful for linguists who want to speed up the visual-making process when working with universal dependencies. It does not have much of an application outside the technical linguistics domain because generating the input files to my program requires prior knowledge of universal dependencies. | This tool would be useful for linguists who want to speed up the visual-making process when working with universal dependencies. It does not have much of an application outside the technical linguistics domain because generating the input files to my program requires prior knowledge of universal dependencies. | ||
Revision as of 06:22, 10 May 2017
Contents
Code
The Problem
For my final project, I decided to create an autoglosser that would automatically convert the universal dependency files we worked with in class into visual form in Latex. There is a Latex package called tikz-dependency that allows for quick input of sentences and its corresponding dependencies, but it still requires the user to manually select each dependency. Therefore, my code automatically generates Latex code that fits the expected format for the tikz-dependency package and therefore can easily be displayed in a graph, as in the following example image:
Although this graph is fancy and colorful, the output of my code is a simplified version that includes all of the most relevant information and has some customizable features. A description of the code, the output, and how to run the program follows.
Previous Work
As discussed in the above section, the tikz-dependency package uses the tikz interface to facilitate the graph-making process. The syntax of a dependency in this format is strikingly similar to that which we saw in class (i.e. #4->6) because both refer to the "from word" and the "to word" using offset from the beginning of the sentence, so it was relatively simple to translate from one form to another.
Who Will Benefit
This tool would be useful for linguists who want to speed up the visual-making process when working with universal dependencies. It does not have much of an application outside the technical linguistics domain because generating the input files to my program requires prior knowledge of universal dependencies.
Basic Solution
My autoglosser parses each line of the CG file and separates it into the relevant portions--the words that make up the sentence, each corresponding part of speech, the other side of the dependency, and the type of dependence relationship. The more specific part-of-speech information present in the CG file is ignored because it would clutter the sentence diagram if it were included.
Therefore, a CG file like the one we looked at in class
"<The>" "The" det def sp @det #1->4 "<quick>" "quick" adj sint @amod #2->4 "<brown>" "brown" adj @amod #3->4 "<fox>" "fox" n sg @nsubj #4->5 "<jumps>" "jump" vblex pres p3 sg @root #5->0 "<over>" "over" pr @case #6->9 "<the>" "the" det def sp @det #7->9 "<lazy>" "lazy" adj sint @amod #8->9 "<dog>" "dog" n sg @obl #9->5 "<in>" "in" pr @case #10->13 "<the>" "the" det def sp @det #11->13 "<green>" "green" adj sint @amod #12->13 "<fields>" "field" n pl @obl #13->5 "<.>" "." sent
is turned into something like this:
words = ['The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog', 'in', 'the', 'green', 'fields', '.'] info = [ ['"The"', 'det', 'def', 'sp', '@det', '#1->4'], ['"quick"', 'adj', 'sint', '@amod', '#2->4'], ['"brown"', 'adj', '@amod', '#3->4'], ['"fox"', 'n', 'sg', '@nsubj', '#4->5'], ['"jump"', 'vblex', 'pres', 'p3', 'sg', '@root', '#5->0'], ['"over"', 'pr', '@case', '#6->9'], ['"the"', 'det', 'def', 'sp', '@det', '#7->9'], ['"lazy"', 'adj', 'sint', '@amod', '#8->9'], ['"dog"', 'n', 'sg', '@obl', '#9->5'], ['"in"', 'pr', '@case', '#10->13'], ['"the"', 'det', 'def', 'sp', '@det', '#11->13'], ['"green"', 'adj', 'sint', '@amod', '#12->13'], ['"field"', 'n', 'pl', '@obl', '#13->5'], ['"."', 'sent']]
The next step that my program takes is using string formatting to extract the relevant aspects of this "info"--namely the "from word", the "to word", and the type of dependency (indicated by the '@' symbol). Once I have all of this information, I can simply plug it into the corresponding locations in the desired format. Therefore, the final Latex code outputted by the simplest version of my program is
\begin{dependency}
\begin{deptext}[column sep=0.2cm]
The \& quick \& brown \& fox \& jumps \& over \& the \& lazy \& dog \& in \& the \& green \& fields \& ROOT \\
\end{deptext}
\depedge{4}{1}{det}
\depedge{4}{2}{amod}
\depedge{4}{3}{amod}
\depedge{5}{4}{nsubj}
\depedge{14}{5}{root}
\depedge{9}{6}{case}
\depedge{9}{7}{det}
\depedge{9}{8}{amod}
\depedge{5}{9}{obl}
\depedge{13}{10}{case}
\depedge{13}{11}{det}
\depedge{13}{12}{amod}
\depedge{5}{13}{obl}
\end{dependency}
Once you add the line \usepackage{tikz-dependency} to a blank Latex file, you can add this code and get the resulting image:
More Complicated Solution
I also added several customizable features to the program. I will briefly explain how each works here.
Visible POS Tags
I added the capability to display the part of speech tags below the text of the sentence. However, since this option may not always be desired, one of the command line arguments for the program toggles it on or off. This is the same graph as above, except with the POS tags visible:
Dependency Filter
In some situations, it may be useful to only view dependencies of a certain type. My tool allows you to optionally specify specific tag names that you want to appear in the graph. If no individual dependency types are listed, it will default to showing all of them. This is the same sentence as the previous examples, but this time with only the 'amod' dependencies displayed:
Batch Diagramming
If this dependency visualization is done on a large scale, it would be tedious to run the program separately for each individual sentence in the corpus. To speed things up, I implemented an option to input a .txt file with a list of filenames. The autoglosser will take that list and generate a separate output file (containing Latex code) for each filename in the list. This makes large scale diagramming more efficient and only requires the user to construct one large file.
Hard-coded Parameters
There were several design choices that I made because I thought they looked the best, but these can be changed with simple edits to the autoglosser.py file.
Column/Row Spacing
I added a default 0.2cm gap between columns (words) and a default 0.2ex gap between rows (only relevant when POS tags are visible).
Word Spacing
When there was a dependency between two consecutive words, the label was sometimes wider than the connecting arrow. To clean up the visual, I added an extra 0.5cm between columns whenever this occurred.
Filename Format
In my code, I hard-coded the program to take input files in the form "<label>_input.txt" and to create output files in the form "<label>_output.txt".
Evaluation
it works, i promise



