English dependency parsing exercise
Dependency parsing with multiple texts
Now, you’re ready to apply the dependency parsing from the previous modules to multiple texts. Use the same five sample texts from the English POS tagging exercises. Follow the same steps from that activity to load the .txt files and process them with nlp_en.pipe() so that you have:
text_files
docs # saved all the outputs from five sample texts
(If you’re not sure about what this means, revisit English POS tagging exercises and repeat the process through Process all text files.)
Inspect dependency annotations across texts
Choose one of the sample texts and inspect its dependency annotations:
doc = docs[0] #sample1.txt
for token in doc:
if not token.is_space:
print(
token.text,
token.pos_,
token.head.text,
token.dep_,
sep="\t"
)
Create CoNLL-U files
Use the doc_to_conllu() function from the CoNLL-U format module to convert each sample text into CoNLL-U format.
First, create a folder for the output files:
from pathlib import Path
output_folder = Path("dependency_output")
output_folder.mkdir(parents=True, exist_ok=True) #makes a new folder
Then convert and save all five texts:
for text_file, doc in zip(text_files, docs):
conllu_text = doc_to_conllu(
doc
)
output_path = (
output_folder /
f"{text_file.stem}.tsv"
)
output_path.write_text(
conllu_text,
encoding="utf-8"
)
print(f"Saved: {output_path.name}")
Your output folder should contain:
sample1.tsv
sample2.tsv
sample3.tsv
sample4.tsv
sample5.tsv
Check Your Output (Validation)
CoNLL-U files are plain-text files with tab-separated fields. Saving them with a .tsv extension allows you to open and inspect them using common programs. For example:
- Excel: Open the
.tsvfile by double-clicking it or selecting File → Open in Excel. The tab-separated CoNLL-U fields should appear in separate columns. - VS Code, TextEdit, or Notepad: Open the file as plain text.
Open at least one .tsv file and inspect the annotations, paying attention to the dependency parsing. Check that:
- Each token is represented using the ten CoNLL-U columns.
HEADspecifies the ID of the token’s syntactic headDEPRELspecifies the dependency relation between the token and its head.- Compare the automated dependency annotations with your own linguistic interpretation: Identify any annotations that seem incorrect, questionable, or inconsistent with your understanding of the sentence. You may need to revisit the definitions of specific dependency relations in UD to interpret the annotations (see the lecture notes, slides, or the paper that we discussed in class).
Document Your Inspection Results
Save your inspection results in a file named inspection_results using one of the following formats: .docx, .pdf, .txt, or .md.
For the issue you identify, include:
- Filename: The
.tsvfile you inspected. - Sentence: The full sentence containing the annotation.
- Annotation: The token(s) and dependency relation(s) you found questionable.
- Explanation: Why you think the annotation may be incorrect or questionable, and what you would expect instead, based on your linguistic interpretation and/or UD guidelines.
You do not need to identify every possible error. Focus on a few representative examples and explain your reasoning. If you do not find any questionable annotations, briefly describe what you examined and why the annotations appear reasonable.
Submission
Please submit the following files with the following naming conventions:
- python code: end_dep.py
- Dependency annotation file 1: sample1.tsv
- Dependency annotation file 2: sample2.tsv
- Dependency annotation file 3: sample3.tsv
- Dependency annotation file 4: sample4.tsv
- Dependency annotation file 5: sample5.tsv
- Inspection results: inspection_results.docx/pdf/txt/md