{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/learning-timestamp-level-representations-for","title":"TS2Vec: Towards Universal Representation of Time Series","arxiv_id":"2106.10466","date":"2021-06-19","proceeding":null,"authors":["Zhihan Yue","Yujing Wang","Juanyong Duan","Tianmeng Yang","Congrui Huang","Yunhai Tong","Bixiong Xu"],"abstract":"This paper presents TS2Vec, a universal framework for learning representations of time series in an arbitrary semantic level. Unlike existing methods, TS2Vec performs contrastive learning in a hierarchical way over augmented context views, which enables a robust contextual representation for each timestamp. Furthermore, to obtain the representation of an arbitrary sub-sequence in the time series, we can apply a simple aggregation over the representations of corresponding timestamps. We conduct extensive experiments on time series classification tasks to evaluate the quality of time series representations. As a result, TS2Vec achieves significant improvement over existing SOTAs of unsupervised time series representation on 125 UCR datasets and 29 UEA datasets. The learned timestamp-level representations also achieve superior results in time series forecasting and anomaly detection tasks. A linear regression trained on top of the learned representations outperforms previous SOTAs of time series forecasting. Furthermore, we present a simple way to apply the learned representations for unsupervised anomaly detection, which establishes SOTA results in the literature. The source code is publicly available at https://github.com/yuezhihan/ts2vec.","url_abs":"https://arxiv.org/abs/2106.10466v4","url_pdf":"https://arxiv.org/pdf/2106.10466v4.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"learning-timestamp-level-representations-for","repo_url":"https://github.com/zhihanyue/ts2vec","is_official":1,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"learning-timestamp-level-representations-for","repo_url":"https://github.com/xingyu617/SimTS_Representation_Learning","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"learning-timestamp-level-representations-for","repo_url":"https://github.com/WenjieDu/PyPOTS","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":null},{"paper_slug":"learning-timestamp-level-representations-for","repo_url":"https://github.com/etna-team/etna","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"anomaly-detection","task_name":"Anomaly Detection"},{"task_slug":"contrastive-learning","task_name":"Contrastive Learning"},{"task_slug":"time-series-1","task_name":"Time Series"},{"task_slug":"time-series","task_name":"Time Series Analysis"},{"task_slug":"time-series-classification","task_name":"Time Series Classification"},{"task_slug":"time-series-forecasting","task_name":"Time Series Forecasting"},{"task_slug":"unsupervised-anomaly-detection","task_name":"Unsupervised Anomaly Detection"}],"methods":[{"method_slug":"contrastive-learning","method_name":"Contrastive Learning"},{"method_slug":"linear-regression","method_name":"Linear Regression"},{"method_slug":"max-pooling","method_name":"Max Pooling"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2106.10466","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2106.10466"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/etna-team/etna","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/xingyu617/SimTS_Representation_Learning","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/zhihanyue/ts2vec","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/WenjieDu/PyPOTS","reach":null}],"summary":{"ran_draft_wrong":3,"ran":1,"ran_violates":2,"ran_fixture":5,"unverified":12},"by_repo_kind":{"official":{"samples":18,"ran":9,"repositories":1},"listed":{"samples":5,"ran":2,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"a4750195b8805692","entry":"cal_metrics","repo":"xingyu617/SimTS_Representation_Learning","repo_kind":"listed","path":"tasks/forecasting.py","file_url":"https://github.com/xingyu617/SimTS_Representation_Learning/blob/HEAD/tasks/forecasting.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a4750195b8805692"}},{"code_sha256_prefix":"c62d56549152cab0","entry":"fit_svm","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"tasks/_eval_protocols.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/tasks/_eval_protocols.py","link_basis":"plan_row","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c62d56549152cab0"}},{"code_sha256_prefix":"fd10054ec4772b80","entry":"generate_binomial_mask","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"models/encoder.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/models/encoder.py","link_basis":"harvester_set","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"fd10054ec4772b80"}},{"code_sha256_prefix":"acda587a1d1be3bf","entry":"generate_continuous_mask","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"models/encoder.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/models/encoder.py","link_basis":"plan_row","language":"python","status":"ran_violates","verification_level":1,"contract_check":"VIOLATES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"acda587a1d1be3bf"}},{"code_sha256_prefix":"50140c8208c033ca","entry":"hierarchical_contrastive_loss","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"models/losses.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/models/losses.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"50140c8208c033ca"}},{"code_sha256_prefix":"c2f2651c9a2df200","entry":"instance_contrastive_loss","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"models/losses.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/models/losses.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c2f2651c9a2df200"}},{"code_sha256_prefix":"5254eb44ce12370e","entry":"pad_nan_to_target","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"utils.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/utils.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5254eb44ce12370e"}},{"code_sha256_prefix":"645d1fdb1dc0e80c","entry":"pkl_load","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"utils.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/utils.py","link_basis":"plan_row","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"OUTPUT_MISDECLARED","metamorphic_tier":"deterministic","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"645d1fdb1dc0e80c"}},{"code_sha256_prefix":"c11f79ab12e7b749","entry":"segment","repo":"xingyu617/SimTS_Representation_Learning","repo_kind":"listed","path":"simts.py","file_url":"https://github.com/xingyu617/SimTS_Representation_Learning/blob/HEAD/simts.py","link_basis":"first_harvest_node","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c11f79ab12e7b749"}},{"code_sha256_prefix":"72ddf2810ea340c7","entry":"temporal_contrastive_loss","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"models/losses.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/models/losses.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"72ddf2810ea340c7"}},{"code_sha256_prefix":"79783deb10f33397","entry":"torch_pad_nan","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"utils.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/utils.py","link_basis":"plan_row","language":"python","status":"ran_fixture","verification_level":1,"contract_check":"RAISES","metamorphic_tier":"invariant","behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"79783deb10f33397"}},{"code_sha256_prefix":"47121228bf8548c3","entry":"eval_ad_result","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"tasks/anomaly_detection.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/tasks/anomaly_detection.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"47121228bf8548c3"}},{"code_sha256_prefix":"ab1fea29d1c61d99","entry":"eval_classification","repo":"xingyu617/SimTS_Representation_Learning","repo_kind":"listed","path":"tasks/classification.py","file_url":"https://github.com/xingyu617/SimTS_Representation_Learning/blob/HEAD/tasks/classification.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"ab1fea29d1c61d99"}},{"code_sha256_prefix":"9fefe06e6c5ec2ba","entry":"eval_classification","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"tasks/classification.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/tasks/classification.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9fefe06e6c5ec2ba"}},{"code_sha256_prefix":"119ba424fe985113","entry":"eval_forecasting","repo":"xingyu617/SimTS_Representation_Learning","repo_kind":"listed","path":"tasks/forecasting.py","file_url":"https://github.com/xingyu617/SimTS_Representation_Learning/blob/HEAD/tasks/forecasting.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"119ba424fe985113"}},{"code_sha256_prefix":"befe203f4fa96ee5","entry":"fit_knn","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"tasks/_eval_protocols.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/tasks/_eval_protocols.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"befe203f4fa96ee5"}},{"code_sha256_prefix":"2309c20a08ac1773","entry":"fit_lr","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"tasks/_eval_protocols.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/tasks/_eval_protocols.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"2309c20a08ac1773"}},{"code_sha256_prefix":"63e193a1a856ae88","entry":"generate_pred_samples","repo":"xingyu617/SimTS_Representation_Learning","repo_kind":"listed","path":"tasks/forecasting.py","file_url":"https://github.com/xingyu617/SimTS_Representation_Learning/blob/HEAD/tasks/forecasting.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"63e193a1a856ae88"}},{"code_sha256_prefix":"9e3f8a516d6d6bda","entry":"get_range_proba","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"tasks/anomaly_detection.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/tasks/anomaly_detection.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9e3f8a516d6d6bda"}},{"code_sha256_prefix":"589ba3938a15e163","entry":"load_UCR","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"datautils.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/datautils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"589ba3938a15e163"}},{"code_sha256_prefix":"017c065ca560f687","entry":"load_UEA","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"datautils.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/datautils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"017c065ca560f687"}},{"code_sha256_prefix":"ee0abcf391ea662f","entry":"load_forecast_npy","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"datautils.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/datautils.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"ee0abcf391ea662f"}},{"code_sha256_prefix":"a537f33988462d8c","entry":"reconstruct_label","repo":"zhihanyue/ts2vec","repo_kind":"official","path":"tasks/anomaly_detection.py","file_url":"https://github.com/zhihanyue/ts2vec/blob/HEAD/tasks/anomaly_detection.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a537f33988462d8c"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}