Simple book categorization based on book summary

I would like to use OpenAI Embeddings API to categorize various media based on their titles and summaries as given by WorldCat. Categories are as follows:

  • Books
    • Action/Adventure
    • Art
    • Biographical
    • Business
    • Comics/Graphic novels
    • Computer/Internet
    • Crafts
    • Crime/Thriller
    • Fantasy
    • Food
    • General Fiction
    • General Non-Fiction
    • Historical Fiction
    • History
    • Home/Garden
    • Horror
    • Humor
    • Illusion/Magic
    • Instructional
    • Juvenile
    • Language
    • Literary Classics
    • Magazines/Newspapers
    • Math/Science/Tech
    • Medical
    • Mixed Collections
    • Mystery
    • Nature
    • Philosophy
    • Pol/Soc/Relig
    • Recreation
    • Romance
    • Science Fiction
    • Self-Help
    • Travel/Adventure
    • True Crime
    • Urban Fantasy
    • Western
    • Young Adult
    • Guitar/Bass Tabs
  • Music
    • Individual Sheet
    • Individual Sheet MP3
    • Instructional Book with Video
    • Instructional Media
    • LTP/Jam With, Lick Library
    • Techniques/QL, Lick Library
    • Complete Editions, Music
    • Music Book
    • Music Book MP3
    • Sheet Collection
    • Sheet Collection MP3
  • Radio
    • Comedy
    • Drama
    • Factual/Documentary
    • Reading

For example, the title (orange dashed) and summary (red dashed) below:

I am just using curl at the moment to get a hang of how to work with the API, but I am ultimately comfortable using any programming language.

Thank you for any assistance.

I believe I came up with a solution.

I create a loop that compares the categories with the target text one category at a time. Then I calculate the cosine similarities between each category and the target text. The closest cosine similarity will identify the closest category label.

I’m going to try to implement this in JavaScript and let you know how it works.

1 Like

Nice. Thanks for stopping back by to let us know. Sorry nobody stepped up to help, but seems you arrived on your own. Thanks again.

1 Like