Lab 3: Text Classification
Remember that a key part of text classification is that the data must have labels telling us what class/category it belongs to. The PCL dataset includes such labels, formatted inside the XML structure. So, we will need to write some code to extract the label for each example. (For inspiration, you can look back to your Lab 2 code, where you were similarly asked to look up a specific attribute in an XML example node).
At the top of pcl_main.py, define your own derived class that inherits from PCLLabels. (If you need a refresher on Python classes and inheritence, you can check out the Python documentation.) Your class should be called BinaryLabels. In your subclass, you will need to implement (override) the _extract_label function that is used by the process function in the base class. (As you may know, in Python, there's no formal version of the private keyword like you might find in Java/C++, but we conventionally add an underscore prefix to member functions that aren't meant to be called from external code) In this function, you should extract the condescension attribute stored in an example taken from the ground-truth XML file. The condescension attribute is stored as the string "true" or "false", hence the name of your subclass.
The skeleton of this class should look something like this:
class BinaryLabels(PCLLabels):
"""docstring"""
def _extract_label(self, example):
"""docstring"""
# your code here
In addition to labels "true" and "false" for condescension, this data also has a categorization scheme for different topical categories of examples under the 'category' attribute (e.g., 'refugees'). This allows us to take a unique strategy to evaluation: rather than holding out a random sample of the data as the test set, we can pick a specific category to use as the test set! For example, we might train on examples from categories other than 'refugees', and then test on the 'refugees' data. This can be an interesting way to check for generalizability of your model!
To avoid writing redundant code, we can re-use our labeler code to extract the category for each example. Just below your BinaryLabels class, add another derived class that inherits from PCLLabels. This class should be called CategoryLabels, and should look very similar, but instead of pulling the true/false condescension label, it should pull the example's category.
(When logged in, completion status appears here.)