{"id":18498214,"url":"https://github.com/albertan017/hicl","last_synced_at":"2025-04-19T20:34:20.834Z","repository":{"id":188939277,"uuid":"679334222","full_name":"albertan017/HICL","owner":"albertan017","description":"The official implementation of the paper HICL: Hashtag-Driven In-Context Learning for Social Media Natural Language Understanding","archived":false,"fork":false,"pushed_at":"2023-08-22T08:37:08.000Z","size":1117,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T13:05:10.847Z","etag":null,"topics":["in-context-learning","nlp"],"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/albertan017.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":"2023-08-16T15:54:36.000Z","updated_at":"2024-11-29T13:35:27.000Z","dependencies_parsed_at":"2024-11-06T18:16:51.847Z","dependency_job_id":null,"html_url":"https://github.com/albertan017/HICL","commit_stats":null,"previous_names":["albertan017/hicl"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertan017%2FHICL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertan017%2FHICL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertan017%2FHICL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/albertan017%2FHICL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/albertan017","download_url":"https://codeload.github.com/albertan017/HICL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249795026,"owners_count":21326776,"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":["in-context-learning","nlp"],"created_at":"2024-11-06T13:38:08.305Z","updated_at":"2025-04-19T20:34:20.815Z","avatar_url":"https://github.com/albertan017.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HICL: Hashtag-Driven In-Context Learning for Social Media Natural Language Understanding\nThe official implementation of the paper HICL: Hashtag-Driven In-Context Learning for Social Media Natural Language Understanding\n\nWe aim to effectively retrieve external data and properly fine-tune bi-directional models to advance generic NLU on social media. \nWe first pre-train an embedding model, #Encoder, to help any social media post in context enriching by retrieving another relevant post; then, we insert trigger terms to fuse the enriched context for language models to refer to in semantics learning under sparsity. \nThe framework can easily be plugged into various task-specific fine-tuning frameworks as external features and broadly benefits downstream social media tasks.\n\nFig.1 The workflow to pre-train #Encoder on 179M Twitter posts, each containing a hashtag. \n#Encoder was pre-trained on pairwise posts, and contrastive learning guided them to learn topic relevance via learning to identify posts with the same hashtag.\nWe randomly noise the hashtags to avoid trivial representation.\n\n![Alt text](figure/encoder-train.png)\n\nFig 2. The workflow of HICL fine-tuning.\nA tweet x is first encoded with \\encoder{} and the output is then used to search the #Database to retrieve the most topic-related tweet x'. \nAfter that, x' and x are paired in concatenation and inserted with trigger terms for task-specific fine-tuning. \nHere HICL can both work for tweets with and without hashtags.\n\n![Alt text](figure/HICL.png)\n\nOur key contributions:\n1. We propose a novel HICL framework for generic social media NLU in data sparsity, which can retrieve topic-related posts and enrich contexts via gradient-searched trigger terms.\n\n2. We develop the first hashtag-driven pre-trained model, #Encoder, leveraging hashtags to learn inter-post topic relevance (for retrieval) via contrastive learning over 179M tweets.\n\n3. We contribute a large corpus with 45M tweets for retrieval, and the experiments on 7 Twitter benchmarks show that HICL advances the overall results of various trendy NLU models.\n\n# Environment\nTo run the code, please install the dependency packages by using the following command:\n```\npip install -r requirements.txt\n```\n# Prepare the Datasets\nPlease refer to the official TweetEval sites to download the datasets:\n\nStance Detection (SemEval-2016 task 6), Emotion Recognition (SemEval-2018 task 1), Irony Detection (SemEval-2018 task 3), Offensive Language Identification (SemEval-2019 task 6), Hate Speech Detection (SemEval-2019 task 5), Humor detection (SemEval-2021 task 7),Sarcasm Detection (SemEval-2022 task 6).\n\nPlease convert the data into {TASK}/train.json, {TASK}/dev.json, {TASK}/test.json with the format: {\"labels\": \"0\", \"text\": \"text\"}, and place them under \"data\" folder\n\n# #Database\nWe will release the 45M #Database upon publication.\n\n# #Encoder\nTo encode a tweet with #Encoder:\n```\nfrom transformers import AutoModel, AutoTokenizer \nhashencoder = AutoModel.from_pretrained(\"albertan017/hashencoder\")\ntokenizer = AutoTokenizer.from_pretrained(\"albertan017/hashencoder\")\ntweet = \"here's a sample tweet for encoding\"\ninput_ids = torch.tensor([tokenizer.encode(tweet)])\nwith torch.no_grad():\n    features = hashencoder(input_ids)  # Models outputs are now tuples\n```\n\n# Run HICL\nTo run the baseline models, please run the bash run_baseline.sh:\n```\nbash run_baseline.sh\n```\n\nTo run the HICL framework, first please run the data preprocess bash, run_HICL_preproecss.sh, it will search for the most topic-related tweets for the benchmark datasets.\n```\nbash run_HICL_preprocess.sh\n```\n\nThen run the bash, run_HICL.sh to reproduce the main results.\n```\nbash run_HICL.sh\n```\n\n# Main Results\nThe main comparison results for HICL is shown as below:\n![Alt text](figure/main_results.png)\n\n# Bugs or Questions\nIf you have any questions related to the code or the paper, feel free to email Hanzhuo Tan (hanzhuo.tan@connect.polyu.hk). If you encounter any problems when using the code, or want to report a bug, you can open an issue. Please try to specify the problem with details so we can help you better and quicker!\n\n# Citation\n```\n@misc{tan2023hicl,\n      title={HICL: Hashtag-Driven In-Context Learning for Social Media Natural Language Understanding}, \n      author={Hanzhuo Tan and Chunpu Xu and Jing Li and Yuqun Zhang and Zeyang Fang and Zeyu Chen and Baohua Lai},\n      year={2023},\n      eprint={2308.09985},\n      archivePrefix={arXiv},\n      primaryClass={cs.CL}\n}\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertan017%2Fhicl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falbertan017%2Fhicl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falbertan017%2Fhicl/lists"}