<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wikis.swarthmore.edu/ling073/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=FTyers1-guest</id>
		<title>LING073 - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://wikis.swarthmore.edu/ling073/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=FTyers1-guest"/>
		<link rel="alternate" type="text/html" href="http://wikis.swarthmore.edu/ling073/Special:Contributions/FTyers1-guest"/>
		<updated>2026-11-14T02:59:53Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.27.7</generator>

	<entry>
		<id>http://wikis.swarthmore.edu/ling073/index.php?title=Dependency_syntax&amp;diff=4627</id>
		<title>Dependency syntax</title>
		<link rel="alternate" type="text/html" href="http://wikis.swarthmore.edu/ling073/index.php?title=Dependency_syntax&amp;diff=4627"/>
				<updated>2017-04-18T18:00:47Z</updated>
		
		<summary type="html">&lt;p&gt;FTyers1-guest: /* Converting between conllu and CG formats */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dependency syntax is a framework for syntax which considers relations between words to be &amp;quot;dependencies&amp;quot;.  It happens to be easy to deal with for various computational linguistics applications: any given token has a &amp;quot;head&amp;quot; (what it depends on) and a &amp;quot;relation&amp;quot; to that head.  E.g., in &amp;quot;a house&amp;quot;, a determiner/article depends on a noun (the noun is the head to the determiner), and the relation is one of &amp;lt;code&amp;gt;det&amp;lt;/code&amp;gt; (depending on the annotation standard used).&lt;br /&gt;
&lt;br /&gt;
[http://universaldependencies.org/ Universal Dependencies] (UD) is a project aimed at designing a standardised set of dependency syntax annotation principles for use across languages, with community-contributed language-specific annotation guidelines.  It&amp;#039;s become pretty popular, and recently released its 2nd version of annotation principles.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Guidance ==&lt;br /&gt;
=== Annotation of a single sentence ===&lt;br /&gt;
&lt;br /&gt;
You start with a sentence:&lt;br /&gt;
 Everyone in this class works on a different language.&lt;br /&gt;
&lt;br /&gt;
You run it through your disambiguator and manually disambiguate as needed so that each word has only one analysis (in CG) format:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;&amp;lt;Everyone&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;everyone&amp;quot; prn ind mf sg&lt;br /&gt;
&amp;quot;&amp;lt;in&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;in&amp;quot; pr&lt;br /&gt;
&amp;quot;&amp;lt;this&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;this&amp;quot; det dem sg&lt;br /&gt;
&amp;quot;&amp;lt;class&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;class&amp;quot; n sg&lt;br /&gt;
&amp;quot;&amp;lt;works&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;work&amp;quot; vblex pres p3 sg&lt;br /&gt;
&amp;quot;&amp;lt;on&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;on&amp;quot; adv&lt;br /&gt;
&amp;quot;&amp;lt;a&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;a&amp;quot; det ind sg&lt;br /&gt;
&amp;quot;&amp;lt;different&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;different&amp;quot; adj&lt;br /&gt;
&amp;quot;&amp;lt;language&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;language&amp;quot; n sg&lt;br /&gt;
&amp;quot;&amp;lt;.&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;.&amp;quot; sent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you consider each word and what other word it depends on and how.  E.g., &amp;quot;Everyone&amp;quot; has an &amp;lt;code&amp;gt;nsubj&amp;lt;/code&amp;gt; dependency on &amp;quot;works&amp;quot; (i.e., it&amp;#039;s its nominal subject).  You then encode these relationships in the sentence:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;&amp;lt;Everyone&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;everyone&amp;quot; prn ind mf sg @nsubj #1-&amp;gt;5&lt;br /&gt;
&amp;quot;&amp;lt;in&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;in&amp;quot; pr @case #2-&amp;gt;4&lt;br /&gt;
&amp;quot;&amp;lt;this&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;this&amp;quot; det dem sg @det #3-&amp;gt;4&lt;br /&gt;
&amp;quot;&amp;lt;class&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;class&amp;quot; n sg @nmod #4-&amp;gt;1&lt;br /&gt;
&amp;quot;&amp;lt;works&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;work&amp;quot; vblex pres p3 sg @root #5-&amp;gt;0&lt;br /&gt;
&amp;quot;&amp;lt;on&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;on&amp;quot; adv @compound:prt #6-&amp;gt;5&lt;br /&gt;
&amp;quot;&amp;lt;a&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;a&amp;quot; det ind sg @det #7-&amp;gt;9&lt;br /&gt;
&amp;quot;&amp;lt;different&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;different&amp;quot; adj @amod #8-&amp;gt;9&lt;br /&gt;
&amp;quot;&amp;lt;language&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;language&amp;quot; n sg @obj #9-&amp;gt;5&lt;br /&gt;
&amp;quot;&amp;lt;.&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;.&amp;quot; sent @punct #10-&amp;gt;5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
When plotted as a tree, this sentence looks like the following:&lt;br /&gt;
&lt;br /&gt;
[[File:UD tree example.png|800px|Dependency tree of &amp;quot;Everyone in this class works on a different language.]]&lt;br /&gt;
&lt;br /&gt;
=== Training a model ===&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[https://ufal.mff.cuni.cz/udpipe UDPipe]&amp;#039;&amp;#039;&amp;#039; is a Free / Open Source tool (should be on the virtual machine) that can train a parser for (read: make a model for how to best guess) UD relations.  It will use whatever information you give it (including lemmas, morphological tags, etc.), and can be trained to guess these as well.&lt;br /&gt;
&lt;br /&gt;
The following command trains a UD parser on &amp;lt;code&amp;gt;corpus.conllu&amp;lt;/code&amp;gt; and outputs the model to &amp;lt;code&amp;gt;abc.model.udpipe&amp;lt;/code&amp;gt;:&lt;br /&gt;
 cat corpus.conllu | udpipe --tagger=none --tokenizer=none --train abc.model.udpipe&lt;br /&gt;
&lt;br /&gt;
=== Testing a model ===&lt;br /&gt;
The following command parses &amp;lt;code&amp;gt;corpus.conllu&amp;lt;/code&amp;gt; using the previously trained &amp;lt;code&amp;gt;abc.model.udpipe&amp;lt;/code&amp;gt;:&lt;br /&gt;
 udpipe --parse abc.model.udpipe corpus.conllu&lt;br /&gt;
&lt;br /&gt;
With the additional switch &amp;lt;code&amp;gt;--accuracy&amp;lt;/code&amp;gt;, it will return measures of its accuracy:&lt;br /&gt;
 udpipe --accuracy --parse abc.model.udpipe corpus.conllu&lt;br /&gt;
&lt;br /&gt;
The two main metrics it returns are the following:&lt;br /&gt;
* Label Attachment Score (&amp;#039;&amp;#039;&amp;#039;LAS&amp;#039;&amp;#039;&amp;#039;): the percentage of tokens that the parser assigned the right dependency head &amp;#039;&amp;#039;and&amp;#039;&amp;#039; relation to.&lt;br /&gt;
* Unlabeled Attachment Score (&amp;#039;&amp;#039;&amp;#039;UAS&amp;#039;&amp;#039;&amp;#039;): the percentage of tokens that the parser assigned the right dependency head to.&lt;br /&gt;
&lt;br /&gt;
=== Removing morphological information ===&lt;br /&gt;
In conllu format, column 3 is for lemmas, column 5 is for POS tags, and column 6 is for other morphological tags.  All values in these columns need to be blanked to &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt; to create a corpus with no morphological information.&lt;br /&gt;
&lt;br /&gt;
The following command will output a corpus with columns 3, 5, and 6 replaced with &amp;lt;code&amp;gt;_&amp;lt;/code&amp;gt;:&lt;br /&gt;
 sed -r &amp;#039;s/[^\t]+/_/3 ; s/[^\t]+/_/5 ; s/[^\t]+/_/6&amp;#039; corpus.conllu&lt;br /&gt;
&lt;br /&gt;
To output it to a new file, just use &amp;lt;code&amp;gt;&amp;amp;gt;&amp;lt;/code&amp;gt;:&lt;br /&gt;
 sed -r &amp;#039;s/[^\t]+/_/3 ; s/[^\t]+/_/5 ; s/[^\t]+/_/6&amp;#039; corpus.conllu &amp;gt; new.corpus.conllu&lt;br /&gt;
&lt;br /&gt;
=== Converting between conllu and CG formats ===&lt;br /&gt;
Try the scripts available in Fran&amp;#039;s [https://github.com/ftyers/ud-scripts ud-scripts] repo, in particular &amp;lt;code&amp;gt;vislcg3-to-conllu.py&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;conllu-to-vislcg.py&amp;lt;/code&amp;gt;.  (And let someone know and/or file a bug report if you notice any problems.) &lt;br /&gt;
&lt;br /&gt;
To convert to conllu format from CG (where &amp;quot;prefix&amp;quot; is just an arbitrary code to prefix to sentence ids):&lt;br /&gt;
 cat corpus.txt | vislcg3-to-conllu.py prefix &amp;gt; corpus.conllu&lt;br /&gt;
&lt;br /&gt;
To convert to CG format from conllu:&lt;br /&gt;
 cat corpus.conllu | conllu-to-vislcg.py &amp;gt; corpus.txt&lt;br /&gt;
&lt;br /&gt;
The conversion may be lossy so don&amp;#039;t expect a 1:1 roundtrip.&lt;br /&gt;
&lt;br /&gt;
=== Useful links ===&lt;br /&gt;
* [[Dependency_syntax/examples|annotated examples from class]]&lt;br /&gt;
* Jonathan&amp;#039;s [http://jonorthwash.github.io/visualise.html UD visualiser tool].&lt;br /&gt;
* Fran&amp;#039;s [[:apertium:Udpipe|UDPipe]] notes.&lt;br /&gt;
* All 37 [http://universaldependencies.org/u/dep/index.html UD relations] (and documentation and examples of each).&lt;br /&gt;
&lt;br /&gt;
== The assignment ==&lt;br /&gt;
This assignment is due before the Tuesday class of the last week of classes (this semester, &amp;#039;&amp;#039;&amp;#039;11:20am on Tuesday, 25 April 2017&amp;#039;&amp;#039;&amp;#039;)&lt;br /&gt;
&lt;br /&gt;
=== Prepare your corpora ===&lt;br /&gt;
# Copy your &amp;lt;code&amp;gt;abc.annotated.basic.txt&amp;lt;/code&amp;gt; corpus (from the previous assignment) to &amp;lt;code&amp;gt;abc.annotated.ud.txt&amp;lt;/code&amp;gt;, and &amp;#039;&amp;#039;&amp;#039;hand-disambiguate&amp;#039;&amp;#039;&amp;#039; it.  In other words, remove all but the correct analysis for each form (i.e., the one that&amp;#039;s right in that sentence).  Add, commit, and push this corpus.&lt;br /&gt;
# Create a &amp;#039;&amp;#039;&amp;#039;second corpus&amp;#039;&amp;#039;&amp;#039; of at least &amp;#039;&amp;#039;&amp;#039;500 characters&amp;#039;&amp;#039;&amp;#039; (or 250 for syllabic writing systems), one sentence per line, and call it &amp;lt;code&amp;gt;abc.annotated2.raw.txt&amp;lt;/code&amp;gt;.  Run it through your tagger and convert to CG format as before.  You can skip the &amp;quot;all and only all possible analyses&amp;quot; step that you did for precision and recall, and just correct it to have the correct analysis for the given sentence.  Call this new file &amp;lt;code&amp;gt;abc.annotated2.ud.txt&amp;lt;/code&amp;gt;, and add, commit, and push these two files.&lt;br /&gt;
&lt;br /&gt;
=== Annotate your corpora for dependencies and post-process ===&lt;br /&gt;
# Add &amp;#039;&amp;#039;&amp;#039;dependency annotation&amp;#039;&amp;#039;&amp;#039; (heads and relations) to both &amp;lt;code&amp;gt;abc.annotated.ud.txt&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;abc.annotated2.ud.txt&amp;lt;/code&amp;gt;.  Commit and push.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Convert these to conllu&amp;#039;&amp;#039;&amp;#039; format, in files with &amp;lt;code&amp;gt;.conllu&amp;lt;/code&amp;gt; extensions instead of &amp;lt;code&amp;gt;.txt&amp;lt;/code&amp;gt; extensions.  Commit and push.&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Remove all morphological information&amp;#039;&amp;#039;&amp;#039;&amp;#039; from &amp;lt;code&amp;gt;abc.annotated.ud.conllu&amp;lt;/code&amp;gt; and call it &amp;lt;code&amp;gt;abc.annotated.nomorph.conllu&amp;lt;/code&amp;gt;.  Add, commit, and push.&lt;br /&gt;
&lt;br /&gt;
=== Train and evaluate a parser ===&lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;Train two parsers&amp;#039;&amp;#039;&amp;#039;: one on &amp;lt;code&amp;gt;abc.annotated.ud.conllu&amp;lt;/code&amp;gt; and one on &amp;lt;code&amp;gt;abc.annotated.nomorph.conllu&amp;lt;/code&amp;gt;.  Call the models &amp;lt;code&amp;gt;abc.withmorph.udpipe&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;abc.nomorph.udpipe&amp;lt;/code&amp;gt;, respectively.  Put them in the &amp;lt;code&amp;gt;dev/&amp;lt;/code&amp;gt; folder of your repository and commit them.&lt;br /&gt;
# Try &amp;#039;&amp;#039;&amp;#039;parsing&amp;#039;&amp;#039;&amp;#039; both &amp;lt;code&amp;gt;abc.annotated.ud.txt&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;abc.annotated2.ud.txt&amp;lt;/code&amp;gt; with each of the models you made.  Make note of the UAS and LAS scores.&lt;br /&gt;
&lt;br /&gt;
=== Documentation ===&lt;br /&gt;
# Make a page on the wiki called &amp;lt;code&amp;gt;Language/Universal_Dependencies&amp;lt;/code&amp;gt;, add it to the category [[:Category:sp17_UD|sp17_UD]] and link to it as a resource from your main wiki page for the language.&lt;br /&gt;
# Add an &amp;quot;Evaluation&amp;quot; section, and make a grid that includes the UAS and LAS scores from your four parsing attempts above, as well as the number of forms (and sentences) in each corpus.&lt;br /&gt;
# Add a &amp;quot;Dependency relations&amp;quot; section, and make a subsection for each of five dependency relations that you used at least twice in your annotation.  For each relation, provide:&lt;br /&gt;
#* A description of the relation, noting various ways it might be used in the language,&lt;br /&gt;
#* Two examples of the relation from your corpus, preferably illustrating what you described.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Assignments]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Dependency syntax]]&lt;/div&gt;</summary>
		<author><name>FTyers1-guest</name></author>	</entry>

	<entry>
		<id>http://wikis.swarthmore.edu/ling073/index.php?title=Hfst-minimise_trick&amp;diff=4189</id>
		<title>Hfst-minimise trick</title>
		<link rel="alternate" type="text/html" href="http://wikis.swarthmore.edu/ling073/index.php?title=Hfst-minimise_trick&amp;diff=4189"/>
				<updated>2017-03-30T18:03:51Z</updated>
		
		<summary type="html">&lt;p&gt;FTyers1-guest: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There&amp;#039;s a &amp;quot;trick&amp;quot; using &amp;lt;code&amp;gt;hfst-minimise&amp;lt;/code&amp;gt; that will get around some issues in converting hfst-format transducers to lttoolbox-format transducers.  That is, if &amp;lt;code&amp;gt;hfst-proc xyz.automorf.hfst&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;lt-proc xyz.automorf.bin&amp;lt;/code&amp;gt; seem to be acting differently, try this trick.&lt;br /&gt;
&lt;br /&gt;
== The trick ==&lt;br /&gt;
In your &amp;lt;code&amp;gt;Makefile.am&amp;lt;/code&amp;gt; file:&lt;br /&gt;
* In the rule for making &amp;lt;code&amp;gt;$(LANG1).automorf.hfst&amp;lt;/code&amp;gt;, pipe the output of &amp;lt;code&amp;gt;hfst-invert&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;hfst-minimise&amp;lt;/code&amp;gt; before piping the output of that into &amp;lt;code&amp;gt;hfst-fst2fst&amp;lt;/code&amp;gt;.  So the relevant part of this line should now look something like this:&lt;br /&gt;
*: ...&amp;lt;code&amp;gt;| hfst-invert | hfst-minimise | hfst-fst2fst -O -o $&amp;lt;/code&amp;gt;&lt;br /&gt;
* In the rule for &amp;lt;code&amp;gt;$(LANG1).autogen.hfst&amp;lt;/code&amp;gt;, first run &amp;lt;code&amp;gt;hfst-minimise&amp;lt;/code&amp;gt; on the input before piping that into &amp;lt;code&amp;gt;hfst-fst2fst&amp;lt;/code&amp;gt;.  That rule should now look something like this:&lt;br /&gt;
*: &amp;lt;code&amp;gt;hfst-minimise $&amp;lt; | hfst-fst2fst -O -o $@&amp;lt;/code&amp;gt;&lt;br /&gt;
* Run &amp;lt;code&amp;gt;make clean&amp;lt;/code&amp;gt;, reinitialise your module (&amp;lt;code&amp;gt;./autogen.sh&amp;lt;/code&amp;gt;), and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; to recompile.&lt;br /&gt;
* Test the output of &amp;lt;code&amp;gt;lt-proc&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hfst-proc&amp;lt;/code&amp;gt; again.&lt;br /&gt;
&lt;br /&gt;
== The reason ==&lt;br /&gt;
&lt;br /&gt;
This happens because there are two fairly minor bugs in the software we use that no-one has got around to fixing yet (partly because there are workarounds):&lt;br /&gt;
&lt;br /&gt;
* In &amp;lt;code&amp;gt;hfst-proc&amp;lt;/code&amp;gt; there is a problem with longest-match left-to-right tokenisation, see the bug description [http://sourceforge.net/tracker/?func=detail&amp;amp;aid=3383731&amp;amp;group_id=224521&amp;amp;atid=1061990 here].&lt;br /&gt;
* In &amp;lt;code&amp;gt;lt-comp&amp;lt;/code&amp;gt; (the ATT compiler) there is a problem with compiling entries where one of the sides begins with an epsilon from the start state but the other doesn&amp;#039;t.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>FTyers1-guest</name></author>	</entry>

	<entry>
		<id>http://wikis.swarthmore.edu/ling073/index.php?title=Hfst-minimise_trick&amp;diff=4188</id>
		<title>Hfst-minimise trick</title>
		<link rel="alternate" type="text/html" href="http://wikis.swarthmore.edu/ling073/index.php?title=Hfst-minimise_trick&amp;diff=4188"/>
				<updated>2017-03-30T17:59:55Z</updated>
		
		<summary type="html">&lt;p&gt;FTyers1-guest: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;There&amp;#039;s a &amp;quot;trick&amp;quot; using &amp;lt;code&amp;gt;hfst-minimise&amp;lt;/code&amp;gt; that will get around some issues in converting hfst-format transducers to lttoolbox-format transducers.  That is, if &amp;lt;code&amp;gt;hfst-proc xyz.automorf.hfst&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;lt-proc xyz.automorf.bin&amp;lt;/code&amp;gt; seem to be acting differently, try this trick.&lt;br /&gt;
&lt;br /&gt;
== The trick ==&lt;br /&gt;
In your &amp;lt;code&amp;gt;Makefile.am&amp;lt;/code&amp;gt; file:&lt;br /&gt;
* In the rule for making &amp;lt;code&amp;gt;$(LANG1).automorf.hfst&amp;lt;/code&amp;gt;, pipe the output of &amp;lt;code&amp;gt;hfst-invert&amp;lt;/code&amp;gt; into &amp;lt;code&amp;gt;hfst-minimise&amp;lt;/code&amp;gt; before piping the output of that into &amp;lt;code&amp;gt;hfst-fst2fst&amp;lt;/code&amp;gt;.  So the relevant part of this line should now look something like this:&lt;br /&gt;
*: ...&amp;lt;code&amp;gt;| hfst-invert | hfst-minimise | hfst-fst2fst -O -o $&amp;lt;/code&amp;gt;&lt;br /&gt;
* In the rule for &amp;lt;code&amp;gt;$(LANG1).autogen.hfst&amp;lt;/code&amp;gt;, first run &amp;lt;code&amp;gt;hfst-minimise&amp;lt;/code&amp;gt; on the input before piping that into &amp;lt;code&amp;gt;hfst-fst2fst&amp;lt;/code&amp;gt;.  That rule should now look something like this:&lt;br /&gt;
*: &amp;lt;code&amp;gt;hfst-minimise $&amp;lt; | hfst-fst2fst -O -o $@&amp;lt;/code&amp;gt;&lt;br /&gt;
* Run &amp;lt;code&amp;gt;make clean&amp;lt;/code&amp;gt;, reinitialise your module (&amp;lt;code&amp;gt;./autogen.sh&amp;lt;/code&amp;gt;), and run &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt; to recompile.&lt;br /&gt;
* Test the output of &amp;lt;code&amp;gt;lt-proc&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;hfst-proc&amp;lt;/code&amp;gt; again.&lt;br /&gt;
&lt;br /&gt;
[[Category:Tutorials]]&lt;/div&gt;</summary>
		<author><name>FTyers1-guest</name></author>	</entry>

	<entry>
		<id>http://wikis.swarthmore.edu/ling073/index.php?title=Morphological_disambiguator&amp;diff=3117</id>
		<title>Morphological disambiguator</title>
		<link rel="alternate" type="text/html" href="http://wikis.swarthmore.edu/ling073/index.php?title=Morphological_disambiguator&amp;diff=3117"/>
				<updated>2017-02-23T09:15:49Z</updated>
		
		<summary type="html">&lt;p&gt;FTyers1-guest: clarifying behaviour&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Why we need disambiguation ==&lt;br /&gt;
Imagine you have a word that has two different tagsets, e.g.&lt;br /&gt;
 ^houses/house&amp;lt;n&amp;gt;&amp;lt;pl&amp;gt;/house&amp;lt;v&amp;gt;&amp;lt;tv&amp;gt;&amp;lt;p3&amp;gt;&amp;lt;sg&amp;gt;$&lt;br /&gt;
 ^this/this&amp;lt;det&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;/this&amp;lt;pron&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;$&lt;br /&gt;
&lt;br /&gt;
Normally your analyser will randomly choose one of these.  Now imagine you have a sentence where the wrong analysis is chosen (in this case, twice!):&lt;br /&gt;
 ^The/The&amp;lt;det&amp;gt;&amp;lt;def&amp;gt;$ ^motel/motel&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$ ^houses/house&amp;lt;n&amp;gt;&amp;lt;pl&amp;gt;$ ^this/this&amp;lt;pron&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;$ ^dog/dog&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$^./.&amp;lt;sent&amp;gt;$&lt;br /&gt;
&lt;br /&gt;
The goal of a disambiguator is to choose the correct analysis based on the surrounding words.&lt;br /&gt;
&lt;br /&gt;
== Using Constraint Grammar to disambiguate ==&lt;br /&gt;
Constraint Grammar (CG) is a formalism that can be used to formalise context sensitive constraints to select or remove analyses from the list of possible analyses.&lt;br /&gt;
&lt;br /&gt;
=== The structure of a CG file ===&lt;br /&gt;
&lt;br /&gt;
At the top you define delimiters.  You can then add lists (which are kind of like sets in twol).  After that you can have any number of constraints.  You can also put lists and constraints in sections. In the original specification for constraint grammar, all the constraints in each section are applied simultaneously, but the sections are applied in order and lists are always global. In the version we use (VISL CG3), the constraints are applied in strict order within the sections.&lt;br /&gt;
&lt;br /&gt;
=== Constraints ===&lt;br /&gt;
&lt;br /&gt;
Think of constraints as a series of heuristics to whittle down the number of analyses until you have as little ambiguity as possible.&lt;br /&gt;
&lt;br /&gt;
The most commonly used constraints are to either &amp;#039;&amp;#039;&amp;#039;remove&amp;#039;&amp;#039;&amp;#039; a reading under a certain condition or &amp;#039;&amp;#039;&amp;#039;select&amp;#039;&amp;#039;&amp;#039; a reading under a certain condition.  The syntax is e.g., &amp;lt;code&amp;gt;REMOVE &amp;lt;target&amp;gt; [contextual tests] ;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Targets can be defined as list names—like &amp;lt;code&amp;gt;Nominals&amp;lt;/code&amp;gt;—or individual tag names, in parentheses—e.g., &amp;lt;code&amp;gt;(n pl)&amp;lt;/code&amp;gt;.  This target identifies the reading to select or remove.&lt;br /&gt;
&lt;br /&gt;
Contextual tests come together in ()s.  All tests must match in order for the constraint to apply.  Inside the parentheses, the first definition is a position: &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; means the current cohort, &amp;lt;code&amp;gt;-1&amp;lt;/code&amp;gt; means the previous cohort, etc.  The rest of the test is what should be matched.  If you want to match any member of the &amp;lt;code&amp;gt;Nominals&amp;lt;/code&amp;gt; set in the previous position, it would be &amp;lt;code&amp;gt;(-1 Nominals)&amp;lt;/code&amp;gt;  You can match tag sequences by adding an extra set of parentheses, e.g. &amp;lt;code&amp;gt;(1 (n pl))&amp;lt;/code&amp;gt; would match a plural noun in the following position.  You can match specific baseforms with quotation marks, e.g. &amp;lt;code&amp;gt;(1 (&amp;quot;house&amp;quot; n))&amp;lt;/code&amp;gt; would match any form of the noun &amp;quot;house&amp;quot; in the following position.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Classroom activity&amp;#039;&amp;#039;&amp;#039;: implement example at top of page.&lt;br /&gt;
&lt;br /&gt;
=== Useful commands ===&lt;br /&gt;
&lt;br /&gt;
The file that your disambiguation constraints are defined in is the &amp;lt;code&amp;gt;apertium-xyz.xyz.rlx&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
==== Getting output before disambiguation ====&lt;br /&gt;
example command:&lt;br /&gt;
 echo &amp;quot;The motel houses this dog&amp;quot; | apertium -d . eng-morph&lt;br /&gt;
example output:&lt;br /&gt;
 ^The/the&amp;lt;det&amp;gt;&amp;lt;def&amp;gt;$ ^motel/motel&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$ ^houses/house&amp;lt;n&amp;gt;&amp;lt;pl&amp;gt;/house&amp;lt;v&amp;gt;&amp;lt;tv&amp;gt;&amp;lt;p3&amp;gt;&amp;lt;sg&amp;gt;$ ^this/this&amp;lt;det&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;/this&amp;lt;prn&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;$ ^dog/dog&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$^./.&amp;lt;sent&amp;gt;$&lt;br /&gt;
&lt;br /&gt;
==== Getting output after disambiguation ====&lt;br /&gt;
example command:&lt;br /&gt;
 echo &amp;quot;The motel houses this dog&amp;quot; | apertium -d . eng-tagger&lt;br /&gt;
example output:&lt;br /&gt;
 ^The&amp;lt;det&amp;gt;&amp;lt;def&amp;gt;$ ^motel&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$ ^house&amp;lt;v&amp;gt;&amp;lt;tv&amp;gt;&amp;lt;p3&amp;gt;&amp;lt;sg&amp;gt;$ ^this&amp;lt;det&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;$ ^dog&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$^.&amp;lt;sent&amp;gt;$&lt;br /&gt;
&lt;br /&gt;
==== Seeing which constraints are doing what ====&lt;br /&gt;
example command:&lt;br /&gt;
 echo &amp;quot;The motel houses this dog&amp;quot; | apertium -d . eng-disam&lt;br /&gt;
example output:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;&amp;lt;The&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;the&amp;quot; det def&lt;br /&gt;
&amp;quot;&amp;lt;motel&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;motel&amp;quot; n sg&lt;br /&gt;
&amp;quot;&amp;lt;houses&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;house&amp;quot; v tv p3 sg&lt;br /&gt;
;	&amp;quot;house&amp;quot; n pl REMOVE:26&lt;br /&gt;
&amp;quot;&amp;lt;this&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;this&amp;quot; det dem sg&lt;br /&gt;
;	&amp;quot;this&amp;quot; prn dem sg REMOVE:29&lt;br /&gt;
&amp;quot;&amp;lt;dog&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;dog&amp;quot; n sg&lt;br /&gt;
&amp;quot;&amp;lt;.&amp;gt;&amp;quot;&lt;br /&gt;
	&amp;quot;.&amp;quot; sent&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Calculating ambiguity ====&lt;br /&gt;
The ambiguity of a corpus is the average number of analyses provided per token.&lt;br /&gt;
You can get the number of tokens like this:&lt;br /&gt;
 cat corpus.txt | lt-proc /path/to/xyz.automorf.bin | sed &amp;#039;s/$\W*\^/$\n^/g&amp;#039; | wc -l&lt;br /&gt;
You can get the number of analyses in your corpus like this:&lt;br /&gt;
 cat corpus.txt | lt-proc /path/to/xyz.automorf.bin | sed &amp;#039;s/$\W*\^/$\n^/g&amp;#039; | cut -f2- -d&amp;#039;/&amp;#039; | sed &amp;#039;s/\//\n/g&amp;#039; | wc -l&lt;br /&gt;
&lt;br /&gt;
Automating it a little further, you can put something like this in a file and run it as a shell script:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
CORPUS=/path/to/corpus.txt&lt;br /&gt;
BIN=/path/to/xyz.automorf.bin&lt;br /&gt;
TOKENS=`cat ${CORPUS} | lt-proc ${BIN} | sed &amp;#039;s/$\W*\^/$\n^/g&amp;#039; | wc -l`&lt;br /&gt;
ANALYSES=`cat ${CORPUS} | lt-proc ${BIN} | sed &amp;#039;s/$\W*\^/$\n^/g&amp;#039; | cut -f2- -d&amp;#039;/&amp;#039; | sed &amp;#039;s/\//\n/g&amp;#039; | wc -l`&lt;br /&gt;
calc $ANALYSES/$TOKENS&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== The assignment ==&lt;br /&gt;
=== Getting set up ===&lt;br /&gt;
# If you&amp;#039;re still working on your [[morphological generator|generator]], finish that first.&lt;br /&gt;
# Commit and push your code at this point, and then &amp;#039;&amp;#039;&amp;#039;add a tag&amp;#039;&amp;#039;&amp;#039; &amp;quot;analyser&amp;quot;:&lt;br /&gt;
#* &amp;lt;code&amp;gt;git tag generator&amp;lt;/code&amp;gt;&lt;br /&gt;
#* Then push the tag to the repo: &amp;lt;code&amp;gt;git push origin generator&amp;lt;/code&amp;gt;&lt;br /&gt;
# Make a &amp;lt;code&amp;gt;Language/Disambiguation&amp;lt;/code&amp;gt; page on the wiki, linked to from your main Language page, with a section titled something like &amp;quot;initial evaluation of ambiguity&amp;quot;.&lt;br /&gt;
#* Add the page to the category [[:Category:Sp17_Disambiguation]].&lt;br /&gt;
# If you haven&amp;#039;t yet, add some punctuation to your transducer.&lt;br /&gt;
#* You can look at the Punctuation lexicon an existing the [http://svn.code.sf.net/p/apertium/svn/languages/apertium-tuk/apertium-tuk.tuk.lexc Turkmen lexc file].&lt;br /&gt;
#* Make sure to define your new multicharacter symbols (i.e., the new tags being used).&lt;br /&gt;
# Find the &amp;quot;xyz-tagger&amp;quot; section of your modes.xml file.  Change &amp;lt;code&amp;gt;cg-proc -w&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;cg-proc -1 -n -w&amp;lt;/code&amp;gt; (but not in the &amp;quot;xyz-disam&amp;quot; section!).  Recompile, commit, push.&lt;br /&gt;
&lt;br /&gt;
=== Identify ambiguity ===&lt;br /&gt;
# Add some more of the most common stems identified by a coverage test.&lt;br /&gt;
# Measure the level of ambiguity in your corpus.&lt;br /&gt;
#* If ambiguity is 1 (i.e., there is no ambiguity), then find any form in the language that can have more than one analysis.  Check a grammar book and dictionary and think creatively.&lt;br /&gt;
#** Implement this into your transducer.&lt;br /&gt;
#** Recompile, and measure level of ambiguity again.&lt;br /&gt;
#* If ambiguity is greater than 1 (i.e., there are at least some ambiguous forms), then figure out what form is ambiguous.&lt;br /&gt;
# List the level of ambiguity into the &amp;quot;initial evaluation of ambiguity&amp;quot; section on the disambig eval wiki page.&lt;br /&gt;
# Find two sentences for two possible readings of the ambiguous term, highlighting the correct reading of the ambiguous form.  For example, if the word was &amp;quot;this&amp;quot;, examples might be:&lt;br /&gt;
#* &amp;lt;code&amp;gt;^This/this&amp;lt;det&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;/&amp;#039;&amp;#039;&amp;#039;this&amp;lt;prn&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;&amp;#039;&amp;#039;&amp;#039;$ ^is/be&amp;lt;v&amp;gt;&amp;lt;iv&amp;gt;&amp;lt;pres&amp;gt;&amp;lt;p3&amp;gt;&amp;lt;sg&amp;gt;$ ^a/a&amp;lt;det&amp;gt;&amp;lt;ind&amp;gt;$ ^dog/dog&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$^./.&amp;lt;sent&amp;gt;$&amp;lt;/code&amp;gt;&lt;br /&gt;
#* &amp;lt;code&amp;gt;^I/I&amp;lt;prn&amp;gt;&amp;lt;pers&amp;gt;&amp;lt;p1&amp;gt;&amp;lt;sg&amp;gt;&amp;lt;sbj&amp;gt;$ ^saw/see&amp;lt;v&amp;gt;&amp;lt;tv&amp;gt;&amp;lt;past&amp;gt;$ ^this/&amp;#039;&amp;#039;&amp;#039;this&amp;lt;det&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;&amp;#039;&amp;#039;&amp;#039;/this&amp;lt;prn&amp;gt;&amp;lt;dem&amp;gt;&amp;lt;sg&amp;gt;$ ^dog/dog&amp;lt;n&amp;gt;&amp;lt;sg&amp;gt;$^./.&amp;lt;sent&amp;gt;$&amp;lt;/code&amp;gt;&lt;br /&gt;
#* Note that it&amp;#039;s best to use real sentences, e.g. from your corpus (or any of the sources that went into the corpus).  If you absolutely must, you may create examples, but make note of this!&lt;br /&gt;
&lt;br /&gt;
=== Write constraints ===&lt;br /&gt;
# Once you have identified examples of ambiguity, come up with &amp;#039;&amp;#039;&amp;#039;prose forms of the constraints&amp;#039;&amp;#039;&amp;#039; you&amp;#039;ll need to write to get the correct form in each of the two sentences.&lt;br /&gt;
#* Be as &amp;#039;&amp;#039;&amp;#039;linguistically sound&amp;#039;&amp;#039;&amp;#039; as you can, so that the constraints will apply in the broadest possible range of scenarios.&lt;br /&gt;
# Using the prose forms of the constraints as guidance (and e.g., providing them as comments in the code), &amp;#039;&amp;#039;&amp;#039;implement CG versions of the constraints&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
#* Be sure to define any sets/lists you might need.&lt;br /&gt;
&lt;br /&gt;
=== Finish up ===&lt;br /&gt;
# Once you get your disambiguator working as exapected, commit your code&lt;br /&gt;
# Measure ambiguity again and add that number to the wiki page.&lt;br /&gt;
&lt;br /&gt;
== More resources ==&lt;br /&gt;
* [[:apertium:Constraint Grammar|Constraint Grammar]] on the Apertium wiki&lt;br /&gt;
* [[:apertium:Apertium and Constraint Grammar|Apertium and Constraint Grammar]] on the Apertium wiki&lt;br /&gt;
* [http://visl.sdu.dk/cg3/single/ Constraint Grammar manual]&lt;br /&gt;
&lt;br /&gt;
[[Category:Assignments]]&lt;br /&gt;
[[Category:Tutorials]]&lt;br /&gt;
[[Category:Disambiguation]]&lt;/div&gt;</summary>
		<author><name>FTyers1-guest</name></author>	</entry>

	</feed>