{"id":21850007,"url":"https://github.com/prithivirajdamodaran/styleformer","last_synced_at":"2025-04-05T03:10:00.399Z","repository":{"id":39613294,"uuid":"376275755","full_name":"PrithivirajDamodaran/Styleformer","owner":"PrithivirajDamodaran","description":"A Neural Language Style Transfer framework to transfer natural language text smoothly between fine-grained language styles like formal/casual, active/passive, and many more. Created by Prithiviraj Damodaran. Open to pull requests and other forms of collaboration.","archived":false,"fork":false,"pushed_at":"2023-12-12T03:47:06.000Z","size":1926,"stargazers_count":482,"open_issues_count":8,"forks_count":64,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-03-29T02:06:20.669Z","etag":null,"topics":["active","formal-languages","informal-sentences","nlp","passive","slang","style-transfer","text-style","text-style-transfer","text-style-transfer-benchmark"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PrithivirajDamodaran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-12T11:41:22.000Z","updated_at":"2025-03-24T11:53:05.000Z","dependencies_parsed_at":"2024-11-03T15:40:36.720Z","dependency_job_id":null,"html_url":"https://github.com/PrithivirajDamodaran/Styleformer","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrithivirajDamodaran%2FStyleformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrithivirajDamodaran%2FStyleformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrithivirajDamodaran%2FStyleformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PrithivirajDamodaran%2FStyleformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PrithivirajDamodaran","download_url":"https://codeload.github.com/PrithivirajDamodaran/Styleformer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247280272,"owners_count":20912967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["active","formal-languages","informal-sentences","nlp","passive","slang","style-transfer","text-style","text-style-transfer","text-style-transfer-benchmark"],"created_at":"2024-11-28T00:15:41.071Z","updated_at":"2025-04-05T03:10:00.382Z","avatar_url":"https://github.com/PrithivirajDamodaran.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPI - License](https://img.shields.io/hexpm/l/plug)](https://github.com/PrithivirajDamodaran/Styleformer/blob/main/LICENSE)\n[![visitors](https://visitor-badge.glitch.me/badge?page_id=Styleformer.count_visitors)](https://visitor-badge.glitch.me)\n\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./images/Styleformer.png\" width=\"65%\" height=\"60%\"/\u003e\n\u003c/p\u003e\n\n# Styleformer\nA Neural Language Style Transfer framework to transfer natural language text smoothly between fine-grained language styles like formal/casual, active/passive, and many more.For instance, understand [What makes text formal or casual/informal](https://www.niu.edu/writingtutorial/style/formal-and-informal-style.shtml).\n\n## Table of contents\n- [Usecases for Styleformer](#usecases-for-styleformer)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n  * [Casual to Formal (Available now !)](#casual-to-formal--available-now---)\n  * [Formal to Casual (Available now !)](#formal-to-casual--available-now---)\n  * [Active to Passive (Available now !)](#active-to-passive--available-now---)\n  * [Passive to Active (Available now !)](#passive-to-active--available-now---)\n- [Knobs](#knobs)\n- [Models](#models)\n- [Dataset](#dataset)\n- [Benchmark](#benchmark)\n- [Streamlit Demo](#streamlit-demo)\n- [References](#references)\n- [Citation](#citation)\n\n## Usecases for Styleformer\n\n**Area 1: Data Augmentation**\n- Augment training datasets with various fine-grained language styles.\n\n**Area 2: Post-processing**\n- Apply style transfers to machine generated text. \n- e.g.\n    - Refine a Summarised text to active voice + formal tone.\n    - Refine a Translated text to more casual tone to reach younger audience.\n\n**Area 3: Controlled paraphrasing**\n- Formal \u003c=\u003e Casual and Active \u003c=\u003e style transfers adds a notion of control over how we paraphrase when compared to free-form paraphrase where there is control or guarantee over the paraphrases.\n\n**Area 4: Assisted writing**\n- Integrate this to any human writing interfaces like email clients, messaging tools or social media post authoring tools. Your creativity is your limit to te uses. \n- e.g.\n    - Polish an email with business tone for professional uses.\n\n## Installation\n```python\npip install git+https://github.com/PrithivirajDamodaran/Styleformer.git\n```\n## Quick Start\n\n~~```python\n[IMPORTANT]\nIf you are using in notebook, use the below line to login:\n       from huggingface_hub import notebook_login\n       notebook_login()\nelse use:\n       huggingface-cli login```~~\n\n### Casual to Formal (Available now !)\n```python\nfrom styleformer import Styleformer\nimport torch\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\n'''\n#uncomment for re-producability\ndef set_seed(seed):\n  torch.manual_seed(seed)\n  if torch.cuda.is_available():\n    torch.cuda.manual_seed_all(seed)\n\nset_seed(1234)\n'''\n\n# style = [0=Casual to Formal, 1=Formal to Casual, 2=Active to Passive, 3=Passive to Active etc..]\nsf = Styleformer(style = 0) \n\nsource_sentences = [\n\"I am quitting my job\",\n\"Jimmy is on crack and can't trust him\",\n\"What do guys do to show that they like a gal?\",\n\"i loooooooooooooooooooooooove going to the movies.\",\n\"That movie was fucking awesome\",\n\"My mom is doing fine\",\n\"That was funny LOL\" , \n\"It's piece of cake, we can do it\",\n\"btw - ur avatar looks familiar\",\n\"who gives a crap?\",\n\"Howdy Lucy! been ages since we last met.\",\n\"Dude, this car's dope!\",\n\"She's my bestie from college\",\n\"I kinda have a feeling that he has a crush on you.\",\n\"OMG! It's finger-lickin' good.\",\n]   \n\nfor source_sentence in source_sentences:\n    target_sentence = sf.transfer(source_sentence)\n    print(\"-\" *100)\n    print(\"[Casual] \", source_sentence)\n    print(\"-\" *100)\n    if target_sentence is not None:\n        print(\"[Formal] \",target_sentence)\n        print()\n    else:\n        print(\"No good quality transfers available !\")\n```\n\n```\n[Casual]  I am quitting my job\n[Formal]  I will be stepping down from my job.\n----------------------------------------------------------------------------------------------------\n[Casual]  Jimmy is on crack and can't trust him\n[Formal]  Jimmy is a crack addict I cannot trust him\n----------------------------------------------------------------------------------------------------\n[Casual]  What do guys do to show that they like a gal?\n[Formal]  What do guys do to demonstrate their affinity for women?\n----------------------------------------------------------------------------------------------------\n[Casual]  i loooooooooooooooooooooooove going to the movies.\n[Formal]  I really like to go to the movies.\n----------------------------------------------------------------------------------------------------\n[Casual]  That movie was fucking awesome\n[Formal]  That movie was wonderful.\n----------------------------------------------------------------------------------------------------\n[Casual]  My mom is doing fine\n[Formal]  My mother is doing well.\n----------------------------------------------------------------------------------------------------\n[Casual]  That was funny LOL\n[Formal]  That was hilarious\n----------------------------------------------------------------------------------------------------\n[Casual]  It's piece of cake, we can do it\n[Formal]  The whole process is simple and is possible.\n----------------------------------------------------------------------------------------------------\n[Casual]  btw - ur avatar looks familiar\n[Formal]  Also, your avatar looks familiar.\n----------------------------------------------------------------------------------------------------\n[Casual]  who gives a crap?\n[Formal]  Who cares?\n----------------------------------------------------------------------------------------------------\n[Casual]  Howdy Lucy! been ages since we last met.\n[Formal]  Hello, Lucy It has been a long time since we last met.\n----------------------------------------------------------------------------------------------------\n[Casual]  Dude, this car's dope!\n[Formal]  I find this car very appealing.\n----------------------------------------------------------------------------------------------------\n[Casual]  She's my bestie from college\n[Formal]  She is my best friend from college.\n----------------------------------------------------------------------------------------------------\n[Casual]  I kinda have a feeling that he has a crush on you.\n[Formal]  I have a feeling that he is attracted to you.\n----------------------------------------------------------------------------------------------------\n[Casual]  OMG! It's finger-lickin' good.\n[Formal]  It is so good, it is delicious.\n----------------------------------------------------------------------------------------------------\n```\n\n### Formal to Casual (Available now !)\n```python\nfrom styleformer import Styleformer\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\n# style = [0=Casual to Formal, 1=Formal to Casual, 2=Active to Passive, 3=Passive to Active etc..]\nsf = Styleformer(style = 1) \nimport torch\ndef set_seed(seed):\n  torch.manual_seed(seed)\n  if torch.cuda.is_available():\n    torch.cuda.manual_seed_all(seed)\n\nset_seed(1212)\n\nsource_sentences = [\n\"I would love to meet attractive men in town\",\n\"Please leave the room now\",\n\"It is a delicious icecream\",\n\"I am not paying this kind of money for that nonsense\",\n\"He is on cocaine and he cannot be trusted with this\",\n\"He is a very nice man and has a charming personality\",\n\"Let us go out for dinner\",\n\"We went to Barcelona for the weekend. We have a lot of things to tell you.\",\n]   \n\nfor source_sentence in source_sentences:\n    # inference_on = [-1=Regular model On CPU, 0-998= Regular model On GPU, 999=Quantized model On CPU]\n    target_sentence = sf.transfer(source_sentence, inference_on=-1, quality_filter=0.95, max_candidates=5)\n    print(\"[Formal] \", source_sentence)\n    if target_sentence is not None:\n        print(\"[Casual] \",target_sentence)\n    else:\n        print(\"No good quality transfers available !\")\n    print(\"-\" *100)        \n```\n\n```\n[Formal]  I would love to meet attractive men in town\n[Casual]  i want to meet hot guys in town\n----------------------------------------------------------------------------------------------------\n[Formal]  Please leave the room now\n[Casual]  leave the room now.\n----------------------------------------------------------------------------------------------------\n[Formal]  It is a delicious icecream\n[Casual]  It is a yummy icecream\n----------------------------------------------------------------------------------------------------\n[Formal]  I am not paying this kind of money for that nonsense\n[Casual]  But I'm not paying this kind of money for that crap\n----------------------------------------------------------------------------------------------------\n[Formal]  He is on cocaine and he cannot be trusted with this\n[Casual]  he is on coke and he can't be trusted with this\n----------------------------------------------------------------------------------------------------\n[Formal]  He is a very nice man and has a charming personality\n[Casual]  he is a really nice guy with a cute personality.\n----------------------------------------------------------------------------------------------------\n[Formal]  Let us go out for dinner\n[Casual]  let's hang out for dinner.\n----------------------------------------------------------------------------------------------------\n[Formal]  We went to Barcelona for the weekend. We have a lot of things to tell you.\n[Casual]  hehe..we went to barcelona for the weekend..we got a lot of things to tell ya..\n----------------------------------------------------------------------------------------------------\n```\n\n### Active to Passive (Available now !)\n```python\n# style = [0=Casual to Formal, 1=Formal to Casual, 2=Active to Passive, 3=Passive to Active etc..]\nsf = Styleformer(style = 2) \n```\n### Passive to Active (Available now !)\n```python\n# style = [0=Casual to Formal, 1=Formal to Casual, 2=Active to Passive, 3=Passive to Active etc..]\nsf = Styleformer(style = 3) \n```\n\n## Knobs\n\n```python\n# inference_on = [-1=Regular model On CPU, 0-998= Regular model On GPU, 999=Quantized model On CPU]\ntarget_sentence = sf.transfer(source_sentence, inference_on=-1, quality_filter=0.95, max_candidates=5)\n```\n\n## Models\n\n|      Model          |Type                          |Status                         \n|----------------|-------------------------------|-----------------------------|\n|[prithivida/informal_to_formal_styletransfer](https://huggingface.co/prithivida/informal_to_formal_styletransfer)|Seq2Seq |Beta\n|[prithivida/formal_to_informal_styletransfer](https://huggingface.co/prithivida/formal_to_informal_styletransfer)|Seq2Seq    |Beta|\n|[prithivida/active_to_passive_styletransfer](https://huggingface.co/prithivida/active_to_passive_styletransfer)|Seq2Seq    |Beta|\n|[prithivida/passive_to_active_styletransfer](https://huggingface.co/prithivida/passive_to_active_styletransfer)|Seq2Seq    |Beta|\n|prithivida/positive_to_negative_styletransfer|Seq2Seq    |WIP|\n|prithivida/negative_to_positive_styletransfer|Seq2Seq    |WIP|\n\n\n## Dataset\n- The casual \u003c=\u003e formal dataset was generated using ideas mentioned in reference paper 1\n- The positive \u003c=\u003e negative dataset was generated using ideas mentioned in reference paper 3\n- Fined tuned on T5 on a Tesla T4 GPU and it took ~2 hours to train each of the above models with batch_size = 16 and epochs = 5.(Will share training args shortly)\n\n## Benchmark\n- TBD\n\n## Streamlit Demo\n```\npip install streamlit\nstreamlit run streamlit_app.py\n```\n\n## References\n- [Formality Style Transfer for Noisy Text: Leveraging Out-of-Domain\nParallel Data for In-Domain Training via POS Masking](https://www.aclweb.org/anthology/D19-5502.pdf)\n- [Generative Text Style Transfer for Improved Language Sophistication](http://cs230.stanford.edu/projects_winter_2020/reports/32069807.pdf)\n- [Delete, Retrieve, Generate: A Simple Approach to Sentiment and Style Transfer](https://arxiv.org/pdf/1804.06437.pdf)\n\n## Citation\n- TBD\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprithivirajdamodaran%2Fstyleformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprithivirajdamodaran%2Fstyleformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprithivirajdamodaran%2Fstyleformer/lists"}