coatlearn 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. coatlearn-0.1.0/.env.example +16 -0
  2. coatlearn-0.1.0/.github/workflows/publish.yml +86 -0
  3. coatlearn-0.1.0/.gitignore +32 -0
  4. coatlearn-0.1.0/CITATION.cff +54 -0
  5. coatlearn-0.1.0/CONTRIBUTING.md +11 -0
  6. coatlearn-0.1.0/LICENSE +202 -0
  7. coatlearn-0.1.0/MANIFEST.in +19 -0
  8. coatlearn-0.1.0/NOTICE +21 -0
  9. coatlearn-0.1.0/PKG-INFO +150 -0
  10. coatlearn-0.1.0/README-PyPI.md +99 -0
  11. coatlearn-0.1.0/README.md +99 -0
  12. coatlearn-0.1.0/README.zh-cn.md +99 -0
  13. coatlearn-0.1.0/SOURCE_MAP.md +17 -0
  14. coatlearn-0.1.0/coatlearn/__init__.py +26 -0
  15. coatlearn-0.1.0/coatlearn/__main__.py +5 -0
  16. coatlearn-0.1.0/coatlearn/annotation/__init__.py +12 -0
  17. coatlearn-0.1.0/coatlearn/annotation/batch.py +90 -0
  18. coatlearn-0.1.0/coatlearn/annotation/dedup.py +135 -0
  19. coatlearn-0.1.0/coatlearn/annotation/definitions.py +216 -0
  20. coatlearn-0.1.0/coatlearn/annotation/judge.py +117 -0
  21. coatlearn-0.1.0/coatlearn/annotation/measurement.py +639 -0
  22. coatlearn-0.1.0/coatlearn/annotation/prediction.py +134 -0
  23. coatlearn-0.1.0/coatlearn/annotation/quality.py +128 -0
  24. coatlearn-0.1.0/coatlearn/annotation/text.py +290 -0
  25. coatlearn-0.1.0/coatlearn/annotation/types.py +388 -0
  26. coatlearn-0.1.0/coatlearn/api.py +1577 -0
  27. coatlearn-0.1.0/coatlearn/causality/__init__.py +5 -0
  28. coatlearn-0.1.0/coatlearn/causality/adjustment.py +183 -0
  29. coatlearn-0.1.0/coatlearn/causality/effects.py +631 -0
  30. coatlearn-0.1.0/coatlearn/causality/graph.py +447 -0
  31. coatlearn-0.1.0/coatlearn/causality/independence.py +19 -0
  32. coatlearn-0.1.0/coatlearn/causality/interface.py +85 -0
  33. coatlearn-0.1.0/coatlearn/causality/learning.py +167 -0
  34. coatlearn-0.1.0/coatlearn/causality/postprocessing.py +126 -0
  35. coatlearn-0.1.0/coatlearn/causality/priors.py +65 -0
  36. coatlearn-0.1.0/coatlearn/causality/statistics.py +83 -0
  37. coatlearn-0.1.0/coatlearn/cli/__init__.py +60 -0
  38. coatlearn-0.1.0/coatlearn/configuration.py +569 -0
  39. coatlearn-0.1.0/coatlearn/discovery/__init__.py +4 -0
  40. coatlearn-0.1.0/coatlearn/discovery/adj.py +703 -0
  41. coatlearn-0.1.0/coatlearn/discovery/mb.py +2521 -0
  42. coatlearn-0.1.0/coatlearn/discovery/pag.py +782 -0
  43. coatlearn-0.1.0/coatlearn/execution.py +200 -0
  44. coatlearn-0.1.0/coatlearn/models/__init__.py +8 -0
  45. coatlearn-0.1.0/coatlearn/models/jev.py +4 -0
  46. coatlearn-0.1.0/coatlearn/models/kev.py +65 -0
  47. coatlearn-0.1.0/coatlearn/models/kev_server.py +119 -0
  48. coatlearn-0.1.0/coatlearn/models/openai.py +531 -0
  49. coatlearn-0.1.0/coatlearn/models/presets.py +121 -0
  50. coatlearn-0.1.0/coatlearn/models/systemone.py +372 -0
  51. coatlearn-0.1.0/coatlearn/utils/__init__.py +1 -0
  52. coatlearn-0.1.0/coatlearn/utils/constants.py +107 -0
  53. coatlearn-0.1.0/coatlearn/utils/logging.py +64 -0
  54. coatlearn-0.1.0/coatlearn/utils/sampling.py +93 -0
  55. coatlearn-0.1.0/coatlearn.egg-info/PKG-INFO +150 -0
  56. coatlearn-0.1.0/coatlearn.egg-info/SOURCES.txt +128 -0
  57. coatlearn-0.1.0/coatlearn.egg-info/dependency_links.txt +1 -0
  58. coatlearn-0.1.0/coatlearn.egg-info/entry_points.txt +2 -0
  59. coatlearn-0.1.0/coatlearn.egg-info/requires.txt +24 -0
  60. coatlearn-0.1.0/coatlearn.egg-info/scm_file_list.json +124 -0
  61. coatlearn-0.1.0/coatlearn.egg-info/scm_version.json +8 -0
  62. coatlearn-0.1.0/coatlearn.egg-info/top_level.txt +1 -0
  63. coatlearn-0.1.0/config/README.md +23 -0
  64. coatlearn-0.1.0/config/adj.toml +109 -0
  65. coatlearn-0.1.0/config/mb.toml +82 -0
  66. coatlearn-0.1.0/config/pag.toml +82 -0
  67. coatlearn-0.1.0/data/LICENSE +22 -0
  68. coatlearn-0.1.0/data/README.md +24 -0
  69. coatlearn-0.1.0/data/apple_reviews_PAG_graph1.csv +1001 -0
  70. coatlearn-0.1.0/data/hillstrom_email_visit_post.csv +19418 -0
  71. coatlearn-0.1.0/docs/.nojekyll +0 -0
  72. coatlearn-0.1.0/docs/README.md +37 -0
  73. coatlearn-0.1.0/docs/_navbar.md +2 -0
  74. coatlearn-0.1.0/docs/_sidebar.md +17 -0
  75. coatlearn-0.1.0/docs/agents.md +13 -0
  76. coatlearn-0.1.0/docs/annotation.md +115 -0
  77. coatlearn-0.1.0/docs/architecture.md +20 -0
  78. coatlearn-0.1.0/docs/assets/docs.css +53 -0
  79. coatlearn-0.1.0/docs/assets/docs.js +84 -0
  80. coatlearn-0.1.0/docs/assets/vendor/LICENSE-docsify +21 -0
  81. coatlearn-0.1.0/docs/assets/vendor/LICENSE-docsify-copy-code +21 -0
  82. coatlearn-0.1.0/docs/assets/vendor/LICENSE-docsify-pagination +21 -0
  83. coatlearn-0.1.0/docs/assets/vendor/LICENSE-prismjs +21 -0
  84. coatlearn-0.1.0/docs/assets/vendor/README.md +14 -0
  85. coatlearn-0.1.0/docs/assets/vendor/docsify-copy-code.min.js +9 -0
  86. coatlearn-0.1.0/docs/assets/vendor/docsify-pagination.min.js +1 -0
  87. coatlearn-0.1.0/docs/assets/vendor/docsify-search.min.js +1 -0
  88. coatlearn-0.1.0/docs/assets/vendor/docsify-vue.css +1 -0
  89. coatlearn-0.1.0/docs/assets/vendor/docsify.min.js +1 -0
  90. coatlearn-0.1.0/docs/assets/vendor/manifest.json +52 -0
  91. coatlearn-0.1.0/docs/assets/vendor/prism-bash.min.js +1 -0
  92. coatlearn-0.1.0/docs/assets/vendor/prism-python.min.js +1 -0
  93. coatlearn-0.1.0/docs/assets/vendor/prism-toml.min.js +1 -0
  94. coatlearn-0.1.0/docs/causality.md +82 -0
  95. coatlearn-0.1.0/docs/concepts.md +51 -0
  96. coatlearn-0.1.0/docs/configuration.md +112 -0
  97. coatlearn-0.1.0/docs/data.md +48 -0
  98. coatlearn-0.1.0/docs/discovery.md +100 -0
  99. coatlearn-0.1.0/docs/index.html +83 -0
  100. coatlearn-0.1.0/docs/kev.md +105 -0
  101. coatlearn-0.1.0/docs/models.md +123 -0
  102. coatlearn-0.1.0/docs/quickstart.md +82 -0
  103. coatlearn-0.1.0/docs/results.md +87 -0
  104. coatlearn-0.1.0/docs/troubleshooting.md +13 -0
  105. coatlearn-0.1.0/docs/zh-cn/README.md +37 -0
  106. coatlearn-0.1.0/docs/zh-cn/_navbar.md +2 -0
  107. coatlearn-0.1.0/docs/zh-cn/_sidebar.md +17 -0
  108. coatlearn-0.1.0/docs/zh-cn/agents.md +13 -0
  109. coatlearn-0.1.0/docs/zh-cn/annotation.md +115 -0
  110. coatlearn-0.1.0/docs/zh-cn/architecture.md +20 -0
  111. coatlearn-0.1.0/docs/zh-cn/causality.md +82 -0
  112. coatlearn-0.1.0/docs/zh-cn/concepts.md +51 -0
  113. coatlearn-0.1.0/docs/zh-cn/configuration.md +112 -0
  114. coatlearn-0.1.0/docs/zh-cn/data.md +48 -0
  115. coatlearn-0.1.0/docs/zh-cn/discovery.md +100 -0
  116. coatlearn-0.1.0/docs/zh-cn/kev.md +105 -0
  117. coatlearn-0.1.0/docs/zh-cn/models.md +123 -0
  118. coatlearn-0.1.0/docs/zh-cn/quickstart.md +82 -0
  119. coatlearn-0.1.0/docs/zh-cn/results.md +87 -0
  120. coatlearn-0.1.0/docs/zh-cn/troubleshooting.md +13 -0
  121. coatlearn-0.1.0/examples/adj.sh +4 -0
  122. coatlearn-0.1.0/examples/mb.sh +4 -0
  123. coatlearn-0.1.0/examples/pag.sh +4 -0
  124. coatlearn-0.1.0/maintainer/publishing.md +63 -0
  125. coatlearn-0.1.0/pyproject.toml +87 -0
  126. coatlearn-0.1.0/setup.cfg +4 -0
  127. coatlearn-0.1.0/skills/coatlearn/SKILL.md +54 -0
  128. coatlearn-0.1.0/skills/coatlearn/references/interfaces.md +53 -0
  129. coatlearn-0.1.0/tools/check_distribution.py +74 -0
  130. coatlearn-0.1.0/tools/prepare_pypi_readme.py +38 -0
@@ -0,0 +1,16 @@
1
+ # Empty template only. Copy to a local .env; never commit a completed file.
2
+ # coatlearn.models.presets read only their required key at run time, after data
3
+ # validation. Default: .env in the Python process's working directory; no parent
4
+ # search or interpolation. Existing process environment values win, even if empty.
5
+ # A loaded key is kept in os.environ; switching env_file does not replace it.
6
+ # dpsk41f (main or annotation):
7
+ DEEPSEEK_API_KEY=
8
+ # jev (annotation only); also used by explicitly configured Jev judge/dedup:
9
+ TYPESAFE_API_KEY=
10
+
11
+ # Optional legacy/advanced ModelConfig variables; only when api_key_env names them.
12
+ # Explicit ModelConfig does not load dotenv automatically. If needed, call:
13
+ # from dotenv import load_dotenv
14
+ # load_dotenv(".env", override=False, interpolate=False)
15
+ COAT_MAIN_API_KEY=
16
+ COAT_ANNOTATION_API_KEY=
@@ -0,0 +1,86 @@
1
+ name: Build and publish Python package
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ target:
7
+ description: Build only, TestPyPI, or PyPI (upload requires a release tag)
8
+ type: choice
9
+ options:
10
+ - build-only
11
+ - testpypi
12
+ - pypi
13
+ default: build-only
14
+ required: true
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ concurrency:
20
+ group: python-publish-${{ github.ref }}
21
+ cancel-in-progress: false
22
+
23
+ jobs:
24
+ build:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - uses: actions/checkout@v4
28
+ with:
29
+ fetch-depth: 0
30
+ - uses: actions/setup-python@v5
31
+ with:
32
+ python-version: '3.11'
33
+ - name: Install build tools
34
+ run: python -m pip install --upgrade build twine
35
+ - name: Verify README and release source
36
+ env:
37
+ PUBLISH_TARGET: ${{ inputs.target }}
38
+ run: |
39
+ python tools/prepare_pypi_readme.py --check
40
+ if [ "$PUBLISH_TARGET" != "build-only" ]; then
41
+ test "$GITHUB_REF_TYPE" = tag || { echo 'Select an existing vX.Y.Z release tag.'; exit 1; }
42
+ git fetch origin main:refs/remotes/origin/main
43
+ git merge-base --is-ancestor "$GITHUB_SHA" origin/main
44
+ test -z "$(git status --porcelain)"
45
+ fi
46
+ - name: Build source distribution and wheel
47
+ run: python -m build
48
+ - name: Check metadata and publication version
49
+ env:
50
+ PUBLISH_TARGET: ${{ inputs.target }}
51
+ run: |
52
+ python -m twine check --strict dist/*
53
+ python tools/check_distribution.py dist --target "$PUBLISH_TARGET"
54
+ - name: Install and inspect public entry points
55
+ run: |
56
+ python -m pip install dist/*.whl
57
+ python -c "from coatlearn import ModelConfig, RunConfig, run_mb, run_pag, run_adj"
58
+ coatlearn --help
59
+ - uses: actions/upload-artifact@v4
60
+ with:
61
+ name: python-distributions
62
+ path: dist/*
63
+ if-no-files-found: error
64
+
65
+ publish:
66
+ if: inputs.target != 'build-only'
67
+ needs: build
68
+ runs-on: ubuntu-latest
69
+ environment:
70
+ name: ${{ inputs.target }}
71
+ url: ${{ inputs.target == 'pypi' && 'https://pypi.org/p/coatlearn' || 'https://test.pypi.org/p/coatlearn' }}
72
+ permissions:
73
+ id-token: write
74
+ steps:
75
+ - uses: actions/download-artifact@v4
76
+ with:
77
+ name: python-distributions
78
+ path: dist/
79
+ - name: Publish to TestPyPI with a short-lived identity
80
+ if: inputs.target == 'testpypi'
81
+ uses: pypa/gh-action-pypi-publish@release/v1
82
+ with:
83
+ repository-url: https://test.pypi.org/legacy/
84
+ - name: Publish to PyPI with a short-lived identity
85
+ if: inputs.target == 'pypi'
86
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,32 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ .eggs/
6
+ build/
7
+ dist/
8
+ .pytest_cache/
9
+ .mypy_cache/
10
+ .ruff_cache/
11
+ .venv/
12
+
13
+ # Experiment outputs written by the core modules / examples
14
+ exp_log_folders/
15
+ example_runs/
16
+ runs/
17
+
18
+ # Local developer instructions and private settings
19
+ AGENTS.md
20
+ config/*.local.toml
21
+ .env
22
+ .env.*
23
+ !.env.example
24
+
25
+ # Only the two documented CSV files are public example inputs.
26
+ data/*.xlsx
27
+ data/*.xls
28
+ data/*.zip
29
+
30
+ # Editor / OS noise
31
+ .DS_Store
32
+ .ipynb_checkpoints/
@@ -0,0 +1,54 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this code, please cite the paper below."
3
+ title: "coatlearn: Causal discovery over unstructured data with large language models"
4
+ type: software
5
+ authors:
6
+ - family-names: Liu
7
+ given-names: Chenxi
8
+ - family-names: Chen
9
+ given-names: Yongqiang
10
+ - family-names: Liu
11
+ given-names: Tongliang
12
+ - family-names: Gong
13
+ given-names: Mingming
14
+ - family-names: Cheng
15
+ given-names: James
16
+ - family-names: Han
17
+ given-names: Bo
18
+ - family-names: Zhang
19
+ given-names: Kun
20
+ url: "https://causalcoat.github.io/"
21
+ repository-code: "https://github.com/causalcoat/COAT-Learn"
22
+ license: Apache-2.0
23
+ keywords:
24
+ - causal discovery
25
+ - causal representation learning
26
+ - large language models
27
+ - markov blanket
28
+ - partial ancestral graph
29
+ - adjustment sets
30
+ preferred-citation:
31
+ type: article
32
+ title: "Discovering and Reasoning of Causality in the Hidden World with Large Language Models"
33
+ authors:
34
+ - family-names: Liu
35
+ given-names: Chenxi
36
+ - family-names: Chen
37
+ given-names: Yongqiang
38
+ - family-names: Liu
39
+ given-names: Tongliang
40
+ - family-names: Gong
41
+ given-names: Mingming
42
+ - family-names: Cheng
43
+ given-names: James
44
+ - family-names: Han
45
+ given-names: Bo
46
+ - family-names: Zhang
47
+ given-names: Kun
48
+ journal: "Journal of Machine Learning Research"
49
+ year: 2026
50
+ volume: 27
51
+ issue: 229
52
+ start: 1
53
+ end: 95
54
+ url: "http://jmlr.org/papers/v27/25-2137.html"
@@ -0,0 +1,11 @@
1
+ # Contributing
2
+
3
+ Contributions should keep each module useful on its own. Model calls belong in `models`, fixed-definition measurement in `annotation`, graph and effect calculations in `causality`, and the three iterative procedures in `discovery`.
4
+
5
+ Discuss changes to research methods separately from interface or directory changes. Factor values follow their definitions. Model confidence is measurement metadata, and user-provided causal assumptions remain labelled as assumptions.
6
+
7
+ Use the Python interface from the [getting-started guide](<docs/quickstart.md>) or inspect commands with `python3 -m coatlearn --help`. Keep examples and documentation aligned with the public interfaces.
8
+
9
+ Keep credentials, private text and local model artifacts out of contributions. Configuration files contain environment-variable names, not keys. Dataset contributions need an explicit origin and redistribution permission.
10
+
11
+ After editing the root README, regenerate the PyPI description with `python3 tools/prepare_pypi_readme.py`. Software releases use Git tags and the manual trusted-publishing workflow; see the [maintainer publishing guide](<maintainer/publishing.md>).
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,19 @@
1
+ include README.md README.zh-cn.md README-PyPI.md CONTRIBUTING.md CITATION.cff SOURCE_MAP.md LICENSE NOTICE .env.example
2
+ recursive-include tools *.py
3
+ recursive-include maintainer *.md
4
+ include data/LICENSE
5
+ recursive-include coatlearn *.py
6
+ recursive-include config *.toml *.md
7
+ recursive-include data *.csv *.md
8
+ recursive-include examples *.sh
9
+ recursive-include docs *.md *.html .nojekyll
10
+ recursive-include docs/assets *.js *.css *.json LICENSE-*
11
+ recursive-include skills *.md
12
+ exclude AGENTS.md
13
+ prune tests
14
+ prune build
15
+ prune dist
16
+ prune example_runs
17
+ prune runs
18
+ global-exclude *.py[cod] __pycache__ .env AGENTS.md
19
+ exclude .env.local .env.production .env.development .env.test
coatlearn-0.1.0/NOTICE ADDED
@@ -0,0 +1,21 @@
1
+ COAT-Learn (coatlearn)
2
+ Copyright 2026 COAT-Learn contributors
3
+
4
+ COAT authors: Chenxi Liu, Yongqiang Chen, Tongliang Liu, Mingming Gong,
5
+ James Cheng, Bo Han and Kun Zhang.
6
+
7
+ This software implements the authors' COAT research framework. The
8
+ publication organizes the maintained research implementation into functional
9
+ modules and renames the Python package and command to coatlearn. Source
10
+ provenance and the scope of these changes are recorded in SOURCE_MAP.md.
11
+
12
+ Software: Apache License, Version 2.0; see LICENSE.
13
+ The two example CSV files: Creative Commons Attribution 4.0 International;
14
+ see data/LICENSE and data/README.md. Third-party software retains its own
15
+ license; dependencies are not relicensed by this notice. Pinned documentation
16
+ assets under docs/assets/vendor retain their accompanying MIT licenses.
17
+
18
+ Research article:
19
+ Discovering and Reasoning of Causality in the Hidden World with Large
20
+ Language Models. Journal of Machine Learning Research 27(229):1–95, 2026.
21
+ https://www.jmlr.org/papers/v27/25-2137.html
@@ -0,0 +1,150 @@
1
+ Metadata-Version: 2.4
2
+ Name: coatlearn
3
+ Version: 0.1.0
4
+ Summary: Causal discovery over unstructured data with large language models (COAT)
5
+ Author: Chenxi Liu, Yongqiang Chen, Tongliang Liu, Mingming Gong, James Cheng, Bo Han, Kun Zhang
6
+ License-Expression: Apache-2.0 AND CC-BY-4.0 AND MIT
7
+ Project-URL: Paper, https://www.jmlr.org/papers/v27/25-2137.html
8
+ Project-URL: Website, https://causalcoat.github.io/
9
+ Project-URL: Documentation, https://causalcoat.github.io/docs/
10
+ Project-URL: Source, https://github.com/causalcoat/COAT-Learn
11
+ Project-URL: Issues, https://github.com/causalcoat/COAT-Learn/issues
12
+ Keywords: causal discovery,causal representation learning,large language models,markov blanket,partial ancestral graph,adjustment sets
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
18
+ Classifier: Operating System :: OS Independent
19
+ Requires-Python: >=3.11
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ License-File: NOTICE
23
+ License-File: data/LICENSE
24
+ License-File: docs/assets/vendor/LICENSE-docsify
25
+ License-File: docs/assets/vendor/LICENSE-docsify-copy-code
26
+ License-File: docs/assets/vendor/LICENSE-docsify-pagination
27
+ License-File: docs/assets/vendor/LICENSE-prismjs
28
+ Requires-Dist: numpy>=1.24
29
+ Requires-Dist: pandas>=2.0
30
+ Requires-Dist: scipy>=1.10
31
+ Requires-Dist: scikit-learn>=1.3
32
+ Requires-Dist: statsmodels>=0.14
33
+ Requires-Dist: tqdm>=4.60
34
+ Requires-Dist: Unidecode>=1.2
35
+ Requires-Dist: nltk>=3.8
36
+ Requires-Dist: openpyxl>=3.1
37
+ Requires-Dist: pydot>=1.4
38
+ Requires-Dist: httpx>=0.24
39
+ Requires-Dist: causal-learn>=0.1.4.5
40
+ Requires-Dist: openai>=1.40
41
+ Requires-Dist: pydantic<3,>=2.8
42
+ Requires-Dist: python-dotenv<2,>=1.0
43
+ Provides-Extra: lingam
44
+ Requires-Dist: lingam>=1.9; extra == "lingam"
45
+ Provides-Extra: kev
46
+ Requires-Dist: torch<2.9,>=2.6; extra == "kev"
47
+ Requires-Dist: transformers<6,>=5.17; extra == "kev"
48
+ Requires-Dist: peft>=0.21; extra == "kev"
49
+ Requires-Dist: accelerate>=1.15; extra == "kev"
50
+ Dynamic: license-file
51
+
52
+ # COAT-Learn (`coatlearn`)
53
+
54
+ [中文](<https://github.com/causalcoat/COAT-Learn/blob/main/README.zh-cn.md>) · [Documentation](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/README.md>) · [Website](https://causalcoat.github.io/) · [Paper](https://www.jmlr.org/papers/v27/25-2137.html)
55
+
56
+ coatlearn is a Python implementation of COAT (Causal Representation Assistant), a research framework for discovering, defining and measuring useful factors in unstructured data, then studying their causal structure and intervention effects. It is for analysts who have ratings, diagnoses or behavior records but do not yet have a complete table of variables to analyze.
57
+
58
+ For example, you have customer ratings and reviews, but do not know which product attributes to measure. COAT asks a language model to propose factors such as sweetness and aroma, assigns values to each observation, and uses statistical feedback to guide further discovery. The language model interprets the source material and defines variables. Statistical methods analyze causal relationships under their assumptions.
59
+
60
+ The paper considers text, images and material that requires external measurement tools. This package's ready-to-use discovery interfaces take a text column; the examples below use reviews and posts. The paper's image and external-tool studies are not direct image or database input interfaces in this package.
61
+
62
+ ## From source material to variables
63
+
64
+ A **factor** is an attribute with a clear meaning and measurement rule. For example, define the sweetness described in a review as “not sweet,” “mildly sweet” or “very sweet,” encoded as 0, 1 and 2. **Factor annotation** applies that same rule to each observation to produce a numeric column. A name alone cannot tell a statistical method whether the attribute provides additional information.
65
+
66
+ If you know which attributes to measure, [annotate your own factors](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/annotation.md>) to build a table for filtering, summaries or modeling. If you do not know which variables are missing, COAT can repeatedly propose and select factors using statistical feedback. This is **factor discovery**.
67
+
68
+ ## From variables to a research question
69
+
70
+ The three methods address progressively deeper analysis goals. You do not need to understand every algorithm before starting.
71
+
72
+ | What you want to understand | Method and result | What the result is useful for |
73
+ | --- | --- | --- |
74
+ | Which attributes jointly provide information about a rating? | COAT-MB seeks a **Markov blanket**: a set of variables that makes the remaining candidates provide no additional information about the target once that set is given. | A variable set for later prediction and investigation. It can include effects and other variables, not only causes. |
75
+ | What causal structure connects these variables? | COAT-PAG adds factors and builds a **partial ancestral graph**: nodes represent variables; edge marks record determined causal information and unresolved directions. | Investigate relationships without drawing a definite arrow where information is insufficient. |
76
+ | How much would an action change an outcome on average? | COAT-ADJ seeks **adjustment sets**, groups of variables that can remove the influence of non-causal paths under the graph and assumptions, then performs **effect estimation**. | For example, study an email's effect on visits without mistaking existing customer differences for the email's effect. |
77
+
78
+ A causal graph can come from COAT, another discovery method or explicit researcher assumptions. With a measured table and a graph, you can [find adjustment sets and estimate effects](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/causality.md>) without discovering factors again. [Understand COAT](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/concepts.md>) explains how these ideas fit together.
79
+
80
+ ## Inspect an example first
81
+
82
+ Use Python 3.11 or newer. Run these commands from the project directory, which contains the [project configuration](<https://github.com/causalcoat/COAT-Learn/blob/main/pyproject.toml>):
83
+
84
+ ```bash
85
+ git clone https://github.com/causalcoat/COAT-Learn.git
86
+ cd COAT-Learn
87
+ python3 -m pip install -e .
88
+ bash examples/mb.sh
89
+ ```
90
+
91
+ The final command reads local data and configuration only. It displays the method, row count, selected columns and model connections. It neither reads credentials nor calls a model.
92
+
93
+ Example scripts load settings from TOML files. TOML is a text format with sections such as `[task]`, so the data, models and statistical settings for an analysis can be kept together.
94
+
95
+ | Example | Input and goal | Saved settings |
96
+ | --- | --- | --- |
97
+ | [MB](<https://github.com/causalcoat/COAT-Learn/blob/main/examples/mb.sh>) | 1,000 synthetic apple reviews; discover factors in `Review` that provide information about `Score`. | [Configuration](<https://github.com/causalcoat/COAT-Learn/blob/main/config/mb.toml>): 5 rounds, Fisher-Z conditional-independence tests, threshold 0.001. |
98
+ | [PAG](<https://github.com/causalcoat/COAT-Learn/blob/main/examples/pag.sh>) | The same apple data; start with measured `Taste` and `Score`, then discover factors to refine their graph. | [Configuration](<https://github.com/causalcoat/COAT-Learn/blob/main/config/pag.toml>): 2 rounds, Fisher-Z, threshold 0.001, graph-search depth 2. |
99
+ | [ADJ](<https://github.com/causalcoat/COAT-Learn/blob/main/examples/adj.sh>) | 2,000 synthetic customer posts with email and visit records; seek adjustment sets and estimate the effect of sending an email on visits. | [Configuration](<https://github.com/causalcoat/COAT-Learn/blob/main/config/adj.toml>): 2 rounds, missing-value Fisher-Z, threshold 0.001, with explicit research assumptions and screening rules. |
100
+
101
+ MB and PAG share one CSV; ADJ uses the other. [Data](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/data.md>) explains their origins and encoding; [configuration](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/configuration.md>) explains the parameters. The ADJ data is not the original randomized Hillstrom experiment and must not be interpreted as randomly assigned treatment.
102
+
103
+ ## Run your first discovery
104
+
105
+ Discovery needs a chat model to propose factors and an annotation model to assign values by rule. All three configurations default to DeepSeek Flash for proposal and local Kev-9B for annotation, definition review and concept deduplication.
106
+
107
+ **Jev** is TypeSafe's hosted decision model for classification, rating and yes/no questions. **Kev** is an independent decision model that you can run locally with a compatible request format. **vLLM** is software for serving chat models, not another discovery method or a requirement for running Kev.
108
+
109
+ For a first attempt, hosted Jev avoids local model deployment. Follow [hosted model setup](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/models.md#connect-hosted-models>) to prepare `DEEPSEEK_API_KEY` and `TYPESAFE_API_KEY`, then run:
110
+
111
+ ```bash
112
+ bash examples/mb.sh --decision-model jev --run --output-dir runs/apple-mb
113
+ ```
114
+
115
+ `--decision-model jev` switches annotation, review and deduplication together; the proposer stays unchanged. Only `--run` calls the models. Hosted calls send the selected text and may incur charges. To use the default Kev instead, first start a server with the [local deployment guide](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/kev.md>).
116
+
117
+ After execution, open `result.json` in the output directory. For MB, `diagnostics.final_blanket` lists the selected names, including the target `Score`. `factors` holds available definitions; `provenance` records model and analysis settings. [Your first analysis](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/quickstart.md>) includes the full steps and code for reading the result.
118
+
119
+ ## Use Python
120
+
121
+ Python and the command line can use the same configuration. The following code checks local input, then explicitly executes the task. Prepare model credentials before execution.
122
+
123
+ ```python
124
+ from coatlearn.configuration import load_task
125
+ from coatlearn.execution import check_task, execute_task
126
+
127
+ plan = load_task("config/mb.toml", decision_model="jev")
128
+ checked = check_task(plan)
129
+ print(checked.summary["rows"])
130
+
131
+ result, directory = execute_task(checked, output_dir="runs/python-mb")
132
+ print(result["diagnostics"]["final_blanket"])
133
+ ```
134
+
135
+ For your own CSV or pandas DataFrame, call `run_mb`, `run_pag` or `run_adj` directly. See [prepare data](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/data.md>) and [discovery interfaces](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/discovery.md>).
136
+
137
+ ## Read next
138
+
139
+ - [Understand COAT](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/concepts.md>): why discover variables, and what the three methods answer.
140
+ - [Your first analysis](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/quickstart.md>): install, run MB and inspect one result.
141
+ - [Annotate factors](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/annotation.md>): apply existing definitions to your material.
142
+ - [Model connections](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/models.md>) and [configuration reference](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/configuration.md>): choose services and adjust settings.
143
+ - [Result reference](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/results.md>): read factors, graphs, adjustment sets and estimates.
144
+ - [Agent use](<https://github.com/causalcoat/COAT-Learn/blob/main/docs/agents.md>): let an agent assist through the public [skill](<https://github.com/causalcoat/COAT-Learn/blob/main/skills/coatlearn/SKILL.md>).
145
+
146
+ See the [paper](https://www.jmlr.org/papers/v27/25-2137.html) for the research, [CITATION.cff](<https://github.com/causalcoat/COAT-Learn/blob/main/CITATION.cff>) for citation details and the [contribution guide](<https://github.com/causalcoat/COAT-Learn/blob/main/CONTRIBUTING.md>) for development. Causal conclusions depend on measurement quality, data and method assumptions. A completed run does not establish those assumptions.
147
+
148
+ ## License
149
+
150
+ The software is licensed under [Apache-2.0](<https://github.com/causalcoat/COAT-Learn/blob/main/LICENSE>). The two example CSV files are licensed separately under [CC BY 4.0](<https://github.com/causalcoat/COAT-Learn/blob/main/data/LICENSE>); see their [source and attribution details](<https://github.com/causalcoat/COAT-Learn/blob/main/data/README.md>). Authors and source provenance are recorded in [NOTICE](<https://github.com/causalcoat/COAT-Learn/blob/main/NOTICE>) and [SOURCE_MAP.md](<https://github.com/causalcoat/COAT-Learn/blob/main/SOURCE_MAP.md>).