Parse String to Syntax Tree (Penn Treebank) in Python

1 min readJan 20, 2022


The Penn Treebank is a massive dataset of annotated & human-corrected words maintained by the University of Pennsylvania, designed to make the process of breaking down and tagging natural language sentences easy & accessible. It’s useful to have a sentence broken down in this way, especially if you’re incorporating other elements of NLP into your application. The /nlp-v2/parse/tree iteration of the Cloudmersive NLP API v2 will empower your application to quickly perform this task. Let’s walk through how to use this in Python.

You can copy in this first snippet to install the Python SDK:

pip install cloudmersive-nlp-api-clientfrom __future__ import print_function
import time
import cloudmersive_nlp_api_client
from import ApiException
from pprint import pprint

After that, you’ll need to authorize your API key in the below snippet:

# Configure API key authorization: Apikey
configuration = cloudmersive_nlp_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'

Finally, you can add in the rest of the callback function below:

# create an instance of the API class
api_instance = cloudmersive_nlp_api_client.ParseApi(cloudmersive_nlp_api_client.ApiClient(configuration))
input = cloudmersive_nlp_api_client.ParseRequest() # ParseRequest | Input string
# Parse string to syntax tree
api_response = api_instance.parse_parse_string(input)
except ApiException as e:
print("Exception when calling ParseApi->parse_parse_string: %s\n" % e)




There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.