Skip to content

perspective.py v0.2.0

Compare
Choose a tag to compare
@Yilmaz4 Yilmaz4 released this 07 Jan 20:40
· 75 commits to main since this release

This is one of biggest updates so far, which includes lots of new features and some bug fixes. I've also added some examples to the examples folder. All changes are listed below:

New features

  • Added format_response, get_highest, get_lowest, show_graph and save_graph functions to perspective/utils.py.
    • format_response formats the dictionary that the analyze function returns to make the response easier to read by a human.
    • get_highest returns the attribute with the highest score value from the dictionary that the analyze function returns.
    • get_lowest returns the attribute with the lowest score value.
    • show_graph uses matplotlib library to create a bar chart, descending according to the score values and shows the graph by popping up an interactive window.
    • save_graph does the same show_graph does but saves the graph as an image instead of showing it by popping up a window.
  • Added perspective.Attributes.All, perspective.Attributes.Production, perspective.Attributes.Experimental and perspective.Attributes.NewYorkTimes which include their related attributes (such as TOXICITY goes to Production and ATTACK_ON_AUTHOR goes to NewYorkTimes). Information about which attribute belongs to which category can be found in this article. Those can be used on attributes argument of analyze function.
  • Added skip_on_lang and skip_on_unknown arguments to analyze function.
    • skip_on_lang tells the function to skip an attribute if the language of the text is not supported by that attribute. The function checks whether the attribute supports that language or not by making a request to the API instead of checking locally, so it may exceed the ratelimit for the API if there are lots of attributes which are expected to not support the language of the text.
    • skip_on_unknown tells the function to skip an attribute if that attribute is unknown. Unlike skip_on_lang, function checks whether the attribute is known or not locally so usage of this wouldn't exceed the ratelimit in case there are lots of unknown attributes requested.

Changes

  • Renamed requestedAttributes argument to attributes.
  • Made attributes argument non-required, and it now defaults to all production-ready attributes (perspective.Attributes.Production).

Bug fixes

  • Fixed UnknownAttributeError exception when perspective.Attributes.IDENTITY_ATTACK and/or perspective.Attributes.THREAT is used in attributes argument of analyze function (there were minor spelling mistakes in those attributes' names).

Code changes

  • Moved attribute classes from main.py to a new file named attributes.py. This didn't affect the functionality of the classes.