{"id":13696772,"url":"https://github.com/xiaohuiyan/BTM","last_synced_at":"2025-05-03T17:32:19.606Z","repository":{"id":25612889,"uuid":"29048060","full_name":"xiaohuiyan/BTM","owner":"xiaohuiyan","description":"Code for Biterm Topic Model (published in WWW 2013)","archived":false,"fork":false,"pushed_at":"2019-11-15T15:45:13.000Z","size":11938,"stargazers_count":403,"open_issues_count":15,"forks_count":138,"subscribers_count":22,"default_branch":"master","last_synced_at":"2024-08-03T18:21:15.557Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/xiaohuiyan/xiaohuiyan.github.io/blob/master/paper/BTM-WWW13.pdf","language":"C++","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/xiaohuiyan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-10T05:16:28.000Z","updated_at":"2024-07-19T17:47:11.000Z","dependencies_parsed_at":"2022-08-13T13:30:23.021Z","dependency_job_id":null,"html_url":"https://github.com/xiaohuiyan/BTM","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaohuiyan%2FBTM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaohuiyan%2FBTM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaohuiyan%2FBTM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xiaohuiyan%2FBTM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xiaohuiyan","download_url":"https://codeload.github.com/xiaohuiyan/BTM/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224369743,"owners_count":17299950,"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":[],"created_at":"2024-08-02T18:00:46.828Z","updated_at":"2024-11-13T00:31:00.324Z","avatar_url":"https://github.com/xiaohuiyan.png","language":"C++","funding_links":[],"categories":["Models"],"sub_categories":["Topic Models for short documents"],"readme":"# Code of Biterm Topic Model\r\n\r\nBiterm Topic Model (BTM) is a word co-occurrence based topic model that learns topics by modeling word-word co-occurrences patterns (e.g., biterms).\r\n(In constrast, LDA and PLSA are word-document co-occurrence topic models, since they model word-document co-occurrences.)\r\n\r\nA biterm consists of two words co-occurring in the same context, for example, in the same short text window. Unlike LDA models the word occurrences, BTM models the biterm occurrences in a corpus. In generation procedure, a biterm is generated by drawn two words independently from a same topic. In other words, the distribution of a biterm b=(wi,wj) is defined as:\r\n\r\n       P(b) = \\sum_k{P(wi|z)*P(wj|z)*P(z)}.\r\n\r\nWith Gibbs sampling algorithm, we can learn topics by estimate P(w|k) and P(z).\r\n\r\nMore detail can be referred to the following paper:\r\n\r\n\u003e Xiaohui Yan, Jiafeng Guo, Yanyan Lan, Xueqi Cheng. A Biterm Topic Model For Short Text. WWW2013.\r\n\r\n## Usage ##\r\nThe code has been test on linux. If you on windows, please install\r\ncygwin (with bc, wc, make).\r\n\r\nThe code includes a runnable example, you can run it *on Linux* by:\r\n\r\n       $ cd script\r\n\t   $ sh runExample.sh\r\n\r\nIt trains BTM over the documents in *sample-data/doc\\_info.txt* and output the topics. The doc\\_info.txt contains all the training documents, where each line represents one document with words separated by space as:\r\n\u003e word1 word2 word3 ....\r\n\r\n(*Note: the sample data is only used for illustration of the usage of the code. It is not the data set used in the paper.*)\r\n\r\nYou can change the paths of data files and parameters in *script/runExample.sh* to run over your own data. \r\n\r\nIndeed, the *runExample.sh* processes the input documents in 4 steps.\r\n\r\n**1. Index the words in the documents**   \r\n   To simplify the main code, we provide a python script to map each word to a unique ID (starts from 0) in the documents. \r\n\r\n    $ python script/indexDocs.py \u003cdoc_pt\u003e \u003cdwid_pt\u003e \u003cvoca_pt\u003e\r\n    \tdoc_pt    input docs to be indexed, each line is a doc with the format \"word word ...\"\r\n    \tdwid_pt   output docs after indexing, each line is a doc with the format \"wordId wordId ...\"\r\n    \tvoca_pt   output vocabulary file, each line is a word with the format \"wordId     word\"\r\n\r\n**2. Topic learning**  \r\n   The next step is to train the model using the documents represented by word ids.    \r\n\r\n    $ ./src/btm est \u003cK\u003e \u003cW\u003e \u003calpha\u003e \u003cbeta\u003e \u003cn_iter\u003e \u003csave_step\u003e \u003cdocs_pt\u003e \u003cmodel_dir\u003e \r\n      K\tint, number of topics\r\n      W\tint, size of vocabulary\r\n      alpha\tdouble, Symmetric Dirichlet prior of P(z), like 1\r\n      beta\tdouble, Symmetric Dirichlet prior of P(w|z), like 0.01\r\n      n_iter\tint, number of iterations of Gibbs sampling\r\n      save_step\tint, steps to save the results\r\n      docs_pt\tstring, path of training docs\r\n      model_dir\tstring, output directory\r\n \r\n   The results will be written into the directory \"model\\_dir\":   \r\n   - k20.pw_z: a K*M matrix for P(w|z), suppose K=20   \r\n   - k20.pz:   a K*1 matrix for P(z), suppose K=20\r\n\r\n**3. Inference topic proportions for documents, i.e., P(z|d)**     \r\n   If you need to analysis the topic proportions of each documents, just run the following common to infer that using the model estimated.\r\n\r\n    $ ./src/btm inf \u003ctype\u003e \u003cK\u003e \u003cdocs_pt\u003e \u003cmodel_dir\u003e\r\n      K\tint, number of topics, like 20\r\n      type\t string, 4 choices:sum_w, sum_b, lda, mix. sum_b is used in our  paper.\r\n      docs_pt\tstring, path of docs to be inferred\r\n      model_dir\tstring, output directory\r\n\r\n   The result will be output to \"model_dir\":   \r\n   - k20.pz_d: a N*K matrix for P(z|d), suppose K=20\r\n  \r\n**4. Results display**    \r\n   Finally, we also provide a python script to illustrate the top words of the topics and their proportions in the collection. \r\n\r\n    $ python script/topicDisplay.py \u003cmodel_dir\u003e \u003cK\u003e \u003cvoca_pt\u003e\r\n      model_dirthe output dir of BTM\r\n      Kthe number of topics\r\n      voca_ptthe vocabulary file\r\n\r\n## Related codes ##\r\n- [Online BTM](https://github.com/xiaohuiyan/OnlineBTM)\r\n- [Bursty BTM](https://github.com/xiaohuiyan/BurstyBTM)\r\n\r\n## History ##\r\n- 2015-01-12, v0.5, improve the usability of the code\r\n- 2012-09-25, v0.1\r\n\r\nIf there is any question, feel free to contact: [Xiaohui Yan](http://xiaohuiyan.github.io \"Xiaohui Yan\")(xhcloud@gmail.com).\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiaohuiyan%2FBTM","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxiaohuiyan%2FBTM","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxiaohuiyan%2FBTM/lists"}