fabricatio 0.2.6.dev8__cp39-cp39-win_amd64.whl → 0.2.7.dev1__cp39-cp39-win_amd64.whl
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.
- fabricatio/_rust.cp39-win_amd64.pyd +0 -0
- fabricatio/_rust.pyi +11 -2
- fabricatio/actions/article.py +74 -44
- fabricatio/actions/output.py +21 -6
- fabricatio/actions/rag.py +49 -2
- fabricatio/capabilities/correct.py +34 -4
- fabricatio/capabilities/rag.py +41 -5
- fabricatio/capabilities/rating.py +4 -4
- fabricatio/capabilities/review.py +2 -2
- fabricatio/capabilities/task.py +3 -3
- fabricatio/config.py +3 -0
- fabricatio/models/action.py +1 -1
- fabricatio/models/extra.py +385 -328
- fabricatio/models/generic.py +60 -9
- fabricatio/models/kwargs_types.py +20 -2
- fabricatio/models/tool.py +6 -2
- fabricatio/models/usages.py +45 -37
- fabricatio-0.2.7.dev1.data/scripts/tdown.exe +0 -0
- {fabricatio-0.2.6.dev8.dist-info → fabricatio-0.2.7.dev1.dist-info}/METADATA +6 -2
- fabricatio-0.2.7.dev1.dist-info/RECORD +42 -0
- fabricatio-0.2.6.dev8.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.6.dev8.dist-info/RECORD +0 -42
- {fabricatio-0.2.6.dev8.dist-info → fabricatio-0.2.7.dev1.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.6.dev8.dist-info → fabricatio-0.2.7.dev1.dist-info}/licenses/LICENSE +0 -0
fabricatio/models/extra.py
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
"""Extra models for built-in actions."""
|
2
2
|
|
3
|
-
from
|
4
|
-
|
5
|
-
from
|
6
|
-
from pydantic import Field
|
3
|
+
from abc import abstractmethod
|
4
|
+
from itertools import chain
|
5
|
+
from typing import Dict, Generator, List, Optional, Self, Tuple, final
|
7
6
|
|
7
|
+
from fabricatio.journal import logger
|
8
|
+
from fabricatio.models.generic import AsPrompt, Base, CensoredAble, Display, PrepareVectorization, ProposedAble, WithRef
|
9
|
+
from fabricatio.models.utils import ok
|
10
|
+
from pydantic import BaseModel, Field
|
8
11
|
|
9
12
|
# <editor-fold desc="ArticleEssence">
|
10
|
-
|
13
|
+
|
14
|
+
|
15
|
+
class Equation(BaseModel):
|
11
16
|
"""Mathematical formalism specification for research contributions.
|
12
17
|
|
13
18
|
Encodes equations with dual representation: semantic meaning and typeset-ready notation.
|
@@ -15,93 +20,123 @@ class Equation(Base):
|
|
15
20
|
|
16
21
|
description: str
|
17
22
|
"""Equation significance structured in three elements:
|
18
|
-
1. Physical/conceptual meaning
|
19
|
-
2. Role in technical workflow
|
20
|
-
3. Relationship to paper's core contribution
|
21
|
-
Example:
|
23
|
+
1. Physical/conceptual meaning of the equation.
|
24
|
+
2. Role in technical workflow (e.g., derivation, optimization, or analysis).
|
25
|
+
3. Relationship to the paper's core contribution (e.g., theoretical foundation, empirical validation).
|
26
|
+
Example: "Defines constrained search space dimensionality reduction. Used in architecture optimization phase (Section 3.2). Enables 40% parameter reduction."
|
27
|
+
"""
|
22
28
|
|
23
29
|
latex_code: str
|
24
30
|
"""LaTeX representation following academic typesetting standards:
|
25
|
-
- Must use equation environment
|
26
|
-
- Multiline equations
|
27
|
-
-
|
28
|
-
Example:
|
31
|
+
- Must use equation environment (e.g., `equation`, `align`).
|
32
|
+
- Multiline equations must align at '=' using `&`.
|
33
|
+
- Include unit annotations where applicable.
|
34
|
+
Example: "\\begin{equation} \\mathcal{L}_{NAS} = \\alpha \\|\\theta\\|_2 + \\beta H(p) \\end{equation}"
|
35
|
+
"""
|
29
36
|
|
30
37
|
|
31
|
-
class Figure(
|
38
|
+
class Figure(BaseModel):
|
32
39
|
"""Visual component specification for technical communication.
|
33
40
|
|
34
|
-
Combines graphical assets with structured academic captioning.
|
41
|
+
Combines graphical assets with structured academic captioning.Extracted from the article provided
|
35
42
|
"""
|
36
43
|
|
37
44
|
description: str
|
38
45
|
"""Figure interpretation guide containing:
|
39
|
-
1. Key visual elements mapping
|
40
|
-
2. Data representation methodology
|
41
|
-
3. Connection to research findings
|
42
|
-
Example:
|
46
|
+
1. Key visual elements mapping (e.g., axes, legends, annotations).
|
47
|
+
2. Data representation methodology (e.g., visualization type, statistical measures).
|
48
|
+
3. Connection to research findings (e.g., supports hypothesis, demonstrates performance).
|
49
|
+
Example: "Architecture search space topology (left) vs. convergence curves (right). Demonstrates NAS efficiency gains through constrained search."
|
50
|
+
"""
|
43
51
|
|
44
52
|
figure_caption: str
|
45
53
|
"""Complete caption following Nature-style guidelines:
|
46
|
-
1. Brief overview statement (首句总结)
|
47
|
-
2. Technical detail layer
|
48
|
-
3. Result implication
|
49
|
-
Example:
|
54
|
+
1. Brief overview statement (首句总结).
|
55
|
+
2. Technical detail layer (e.g., data sources, experimental conditions).
|
56
|
+
3. Result implication (e.g., key insights, implications for future work).
|
57
|
+
Example: "Figure 3: Differentiable NAS framework. (a) Search space topology with constrained dimensions. (b) Training convergence across language pairs. Dashed lines indicate baseline methods."
|
58
|
+
"""
|
59
|
+
|
60
|
+
figure_serial_number: int
|
61
|
+
"""The Image serial number extracted from the Markdown article provided, the path usually in the form of ``, in this case the serial number is `1`"""
|
62
|
+
|
63
|
+
|
64
|
+
class Algorithm(BaseModel):
|
65
|
+
"""Algorithm specification for research contributions."""
|
50
66
|
|
51
|
-
|
52
|
-
"""
|
53
|
-
Strict validation requirements:
|
54
|
-
- Absolute path under /assets/figures/
|
55
|
-
- Naming convention: fig[chapter]-[section]_[description].pdf
|
56
|
-
Example: '/assets/figures/fig3-2_nas_convergence.pdf'"""
|
67
|
+
title: str
|
68
|
+
"""Algorithm title with technical focus descriptor (e.g., 'Gradient Descent Optimization').
|
57
69
|
|
70
|
+
Tip: Do not attempt to translate the original element titles when generating JSON.
|
71
|
+
"""
|
72
|
+
|
73
|
+
description: str
|
74
|
+
"""Algorithm description with technical focus descriptor:
|
75
|
+
- Includes input/output specifications.
|
76
|
+
- Describes key steps and their purpose.
|
77
|
+
- Explains its role in the research workflow.
|
78
|
+
Example: "Proposed algorithm for neural architecture search. Inputs include search space constraints and training data. Outputs optimized architecture."
|
79
|
+
"""
|
80
|
+
|
81
|
+
|
82
|
+
class Table(BaseModel):
|
83
|
+
"""Table specification for research contributions."""
|
84
|
+
|
85
|
+
title: str
|
86
|
+
"""Table title with technical focus descriptor (e.g., 'Comparison of Model Performance Metrics').
|
87
|
+
|
88
|
+
Tip: Do not attempt to translate the original element titles when generating JSON.
|
89
|
+
"""
|
58
90
|
|
59
|
-
|
91
|
+
description: str
|
92
|
+
"""Table description with technical focus descriptor:
|
93
|
+
- Includes data source and structure.
|
94
|
+
- Explains key columns/rows and their significance.
|
95
|
+
- Connects to research findings or hypotheses.
|
96
|
+
Example: "Performance metrics for different architectures. Columns represent accuracy, F1-score, and inference time. Highlights efficiency gains of proposed method."
|
97
|
+
"""
|
98
|
+
|
99
|
+
|
100
|
+
class Highlightings(BaseModel):
|
60
101
|
"""Technical showcase aggregator for research artifacts.
|
61
102
|
|
62
103
|
Curates core scientific components with machine-parseable annotations.
|
63
104
|
"""
|
64
105
|
|
65
|
-
highlighted_equations: List[Equation]
|
66
|
-
"""3-5 pivotal equations representing theoretical contributions
|
67
|
-
Each must
|
68
|
-
-
|
69
|
-
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
highlighted_algorithms: List[
|
74
|
-
"""
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
2. While not converged:
|
82
|
-
a. Compute gradient ▽θ
|
83
|
-
b. Update architecture parameters...'"""
|
106
|
+
highlighted_equations: List[Equation]
|
107
|
+
"""3-5 pivotal equations representing theoretical contributions:
|
108
|
+
- Each equation must be wrapped in $$ for display math.
|
109
|
+
- Contain at least one novel operator/symbol.
|
110
|
+
- Be referenced in Methods/Results sections.
|
111
|
+
Example: Equation describing proposed loss function.
|
112
|
+
"""
|
113
|
+
|
114
|
+
highlighted_algorithms: List[Algorithm]
|
115
|
+
"""1-2 key algorithms demonstrating methodological contributions:
|
116
|
+
- Include pseudocode or step-by-step descriptions.
|
117
|
+
- Highlight innovation in computational approach.
|
118
|
+
Example: Algorithm for constrained search space exploration.
|
119
|
+
|
120
|
+
Tip: Do not attempt to translate the original element titles when generating JSON.
|
121
|
+
"""
|
84
122
|
|
85
|
-
highlighted_figures: List[Figure]
|
123
|
+
highlighted_figures: List[Figure]
|
86
124
|
"""4-6 key figures demonstrating:
|
87
|
-
1. Framework overview (1 required)
|
88
|
-
2. Quantitative results (2-3 required)
|
89
|
-
3. Ablation studies (1 optional)
|
90
|
-
Each must appear in Results/Discussion chapters.
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
-
|
96
|
-
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
Ours & 32.4 & -41\\%† \\
|
103
|
-
\bottomrule
|
104
|
-
\\end{tabular}"""
|
125
|
+
1. Framework overview (1 required).
|
126
|
+
2. Quantitative results (2-3 required).
|
127
|
+
3. Ablation studies (1 optional).
|
128
|
+
Each must appear in Results/Discussion chapters.
|
129
|
+
Example: Figure showing architecture topology and convergence curves.
|
130
|
+
"""
|
131
|
+
|
132
|
+
highlighted_tables: List[Table]
|
133
|
+
"""2-3 key tables summarizing:
|
134
|
+
- Comparative analysis of methods.
|
135
|
+
- Empirical results supporting claims.
|
136
|
+
Example: Table comparing model performance across datasets.
|
137
|
+
|
138
|
+
Tip: Do not attempt to translate the original element titles when generating JSON.
|
139
|
+
"""
|
105
140
|
|
106
141
|
|
107
142
|
class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
@@ -109,6 +144,7 @@ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
|
109
144
|
|
110
145
|
Encodes research artifacts with dual human-machine interpretability.
|
111
146
|
"""
|
147
|
+
|
112
148
|
title: str = Field(...)
|
113
149
|
"""Exact title of the original article without any modification.
|
114
150
|
Must be preserved precisely from the source material without:
|
@@ -116,7 +152,7 @@ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
|
116
152
|
- Paraphrasing
|
117
153
|
- Adding/removing words
|
118
154
|
- Altering style or formatting
|
119
|
-
|
155
|
+
"""
|
120
156
|
|
121
157
|
authors: List[str]
|
122
158
|
"""Original author names exactly as they appear in the source document. No translation or paraphrasing.
|
@@ -129,7 +165,7 @@ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
|
129
165
|
publication_year: int
|
130
166
|
"""Publication timestamp in ISO 8601 (YYYY format)."""
|
131
167
|
|
132
|
-
highlightings: Highlightings
|
168
|
+
highlightings: Highlightings
|
133
169
|
"""Technical highlight reel containing:
|
134
170
|
- Core equations (Theory)
|
135
171
|
- Key algorithms (Implementation)
|
@@ -137,9 +173,7 @@ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
|
137
173
|
- Benchmark tables (Evaluation)"""
|
138
174
|
|
139
175
|
domain: List[str]
|
140
|
-
"""
|
141
|
-
Exactly 2-3 categories required.
|
142
|
-
Example: ['Computing methodologies → Machine learning']"""
|
176
|
+
"""Domain tags for research focus."""
|
143
177
|
|
144
178
|
abstract: str = Field(...)
|
145
179
|
"""Three-paragraph structured abstract:
|
@@ -201,7 +235,7 @@ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
|
|
201
235
|
# </editor-fold>
|
202
236
|
|
203
237
|
|
204
|
-
class ArticleProposal(
|
238
|
+
class ArticleProposal(CensoredAble, Display, WithRef[str], AsPrompt):
|
205
239
|
"""Structured proposal for academic paper development with core research elements.
|
206
240
|
|
207
241
|
Guides LLM in generating comprehensive research proposals with clearly defined components.
|
@@ -210,63 +244,80 @@ class ArticleProposal(ProposedAble, Display):
|
|
210
244
|
title: str = Field(...)
|
211
245
|
"""Paper title in academic style (Title Case, 8-15 words). Example: 'Exploring Neural Architecture Search for Low-Resource Machine Translation'"""
|
212
246
|
|
213
|
-
focused_problem: List[str]
|
247
|
+
focused_problem: List[str]
|
214
248
|
"""Specific research problem(s) or question(s) addressed (list of 1-3 concise statements).
|
215
249
|
Example: ['NAS computational overhead in low-resource settings', 'Architecture transferability across language pairs']"""
|
216
250
|
|
217
|
-
research_aim: List[str]
|
251
|
+
research_aim: List[str]
|
218
252
|
"""Primary research objectives (list of 2-4 measurable goals).
|
219
253
|
Example: ['Develop parameter-efficient NAS framework', 'Establish cross-lingual architecture transfer metrics']"""
|
220
254
|
|
221
|
-
research_methods: List[str]
|
255
|
+
research_methods: List[str]
|
222
256
|
"""Methodological components (list of techniques/tools).
|
223
257
|
Example: ['Differentiable architecture search', 'Transformer-based search space', 'Multi-lingual perplexity evaluation']"""
|
224
258
|
|
225
|
-
technical_approaches: List[str]
|
259
|
+
technical_approaches: List[str]
|
260
|
+
"""Technical approaches"""
|
226
261
|
|
262
|
+
def _as_prompt_inner(self) -> Dict[str, str]:
|
263
|
+
return {"ArticleBriefing": self.referenced, "ArticleProposal": self.display()}
|
227
264
|
|
228
|
-
# <editor-fold desc="ArticleOutline">
|
229
|
-
class ArticleSubsectionOutline(Base):
|
230
|
-
"""Atomic research component specification for academic paper generation."""
|
231
265
|
|
232
|
-
|
233
|
-
"""
|
234
|
-
- Title Case with 4-8 word limit
|
235
|
-
- Contains method and domain components
|
236
|
-
Example: 'Differentiable Search Space Optimization'"""
|
266
|
+
class ArticleRef(CensoredAble):
|
267
|
+
"""Reference to a specific section or subsection within an article.
|
237
268
|
|
238
|
-
|
239
|
-
"""
|
240
|
-
1. Technical Core: Method/algorithm/formalism (1 sentence)
|
241
|
-
2. Structural Role: Placement rationale in section (1 clause)
|
242
|
-
3. Research Value: Contribution to paper's thesis (1 clause)
|
269
|
+
Always instantiated with a fine-grind reference to a specific subsection if possible.
|
270
|
+
"""
|
243
271
|
|
244
|
-
|
245
|
-
|
246
|
-
maintaining search space diversity while ensuring convergence.'"""
|
272
|
+
referred_chapter_title: str
|
273
|
+
"""Full title of the chapter that contains the referenced section."""
|
247
274
|
|
275
|
+
referred_section_title: Optional[str] = None
|
276
|
+
"""Full title of the section that contains the referenced subsection. Defaults to None if not applicable, which means the reference is to the entire chapter."""
|
248
277
|
|
249
|
-
|
250
|
-
"""
|
278
|
+
referred_subsection_title: Optional[str] = None
|
279
|
+
"""Full title of the subsection that contains the referenced paragraph. Defaults to None if not applicable, which means the reference is to the entire section."""
|
251
280
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
281
|
+
def __hash__(self) -> int:
|
282
|
+
"""Overrides the default hash function to ensure consistent hashing across instances."""
|
283
|
+
return hash((self.referred_chapter_title, self.referred_section_title, self.referred_subsection_title))
|
284
|
+
|
285
|
+
|
286
|
+
# <editor-fold desc="ArticleOutline">
|
287
|
+
class ArticleOutlineBase(Base):
|
288
|
+
"""Atomic research component specification for academic paper generation."""
|
289
|
+
|
290
|
+
writing_aim: List[str]
|
291
|
+
"""Required: List of specific rhetorical objectives (3-5 items).
|
292
|
+
Format: Each item must be an actionable phrase starting with a verb.
|
293
|
+
Example: ['Establish metric validity', 'Compare with baseline approaches',
|
294
|
+
'Justify threshold selection']"""
|
295
|
+
support_to: List[ArticleRef]
|
296
|
+
"""Required: List of ArticleRef objects identifying components this section provides evidence for.
|
297
|
+
Format: Each reference must point to a specific chapter, section, or subsection.
|
298
|
+
Note: References form a directed acyclic graph in the document structure."""
|
299
|
+
|
300
|
+
depend_on: List[ArticleRef]
|
301
|
+
"""Required: List of ArticleRef objects identifying components this section builds upon.
|
302
|
+
Format: Each reference must point to a previously defined chapter, section, or subsection.
|
303
|
+
Note: Circular dependencies are not permitted."""
|
257
304
|
|
258
305
|
description: str = Field(...)
|
259
|
-
"""
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
306
|
+
"""Description of the research component in academic style."""
|
307
|
+
title: str = Field(...)
|
308
|
+
"""Title of the research component in academic style."""
|
309
|
+
|
310
|
+
|
311
|
+
class ArticleSubsectionOutline(ArticleOutlineBase):
|
312
|
+
"""Atomic research component specification for academic paper generation."""
|
264
313
|
|
265
|
-
Example: 'Implements constrained NAS framework building on Section 2's
|
266
|
-
theoretical foundations. Introduces dynamic resource allocation mechanism.
|
267
|
-
Directly supports Results section through ablation study parameters.'"""
|
268
314
|
|
269
|
-
|
315
|
+
class ArticleSectionOutline(ArticleOutlineBase):
|
316
|
+
"""Methodological unit organizing related technical components."""
|
317
|
+
|
318
|
+
subsections: List[ArticleSubsectionOutline] = Field(
|
319
|
+
...,
|
320
|
+
)
|
270
321
|
"""IMRaD-compliant substructure with technical progression:
|
271
322
|
1. Conceptual Framework
|
272
323
|
2. Methodological Details
|
@@ -284,27 +335,12 @@ class ArticleSectionOutline(Base):
|
|
284
335
|
]"""
|
285
336
|
|
286
337
|
|
287
|
-
class ArticleChapterOutline(
|
338
|
+
class ArticleChapterOutline(ArticleOutlineBase):
|
288
339
|
"""Macro-structural unit implementing standard academic paper organization."""
|
289
340
|
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
- Matches standard paper sections
|
294
|
-
Example: 'Multilingual Evaluation Results'"""
|
295
|
-
|
296
|
-
description: str = Field(...)
|
297
|
-
"""Strategic chapter definition containing:
|
298
|
-
1. Research Phase: Introduction/Methods/Results/etc.
|
299
|
-
2. Chapter Objectives: 3-5 specific goals
|
300
|
-
3. Thesis Alignment: Supported claims/contributions
|
301
|
-
4. Structural Flow: Adjacent chapter relationships
|
302
|
-
|
303
|
-
Example: 'Presents cross-lingual NAS results across 10 language pairs.
|
304
|
-
Validates efficiency claims from Introduction. Provides empirical basis
|
305
|
-
for Discussion chapter. Contrasts with single-language baselines.'"""
|
306
|
-
|
307
|
-
sections: List[ArticleSectionOutline] = Field(..., min_length=3, max_length=5)
|
341
|
+
sections: List[ArticleSectionOutline] = Field(
|
342
|
+
...,
|
343
|
+
)
|
308
344
|
"""Standard academic progression implementing chapter goals:
|
309
345
|
1. Context Establishment
|
310
346
|
2. Technical Presentation
|
@@ -322,7 +358,7 @@ class ArticleChapterOutline(Base):
|
|
322
358
|
]"""
|
323
359
|
|
324
360
|
|
325
|
-
class ArticleOutline(
|
361
|
+
class ArticleOutline(Display, CensoredAble, WithRef[ArticleProposal]):
|
326
362
|
"""Complete academic paper blueprint with hierarchical validation."""
|
327
363
|
|
328
364
|
title: str = Field(...)
|
@@ -344,7 +380,7 @@ class ArticleOutline(ProposedAble, Display, FinalizedDumpAble):
|
|
344
380
|
across 50+ languages, enabling efficient architecture discovery with
|
345
381
|
60% reduced search costs.'"""
|
346
382
|
|
347
|
-
chapters: List[ArticleChapterOutline]
|
383
|
+
chapters: List[ArticleChapterOutline]
|
348
384
|
"""IMRaD structure with enhanced academic validation:
|
349
385
|
1. Introduction: Problem Space & Contributions
|
350
386
|
2. Background: Theoretical Foundations
|
@@ -355,6 +391,9 @@ class ArticleOutline(ProposedAble, Display, FinalizedDumpAble):
|
|
355
391
|
7. Conclusion: Synthesis & Future Work
|
356
392
|
8. Appendices: Supplementary Materials"""
|
357
393
|
|
394
|
+
abstract: str = Field(...)
|
395
|
+
"""The abstract is a concise summary of the academic paper's main findings."""
|
396
|
+
|
358
397
|
def finalized_dump(self) -> str:
|
359
398
|
"""Generates standardized hierarchical markup for academic publishing systems.
|
360
399
|
|
@@ -389,7 +428,7 @@ class ArticleOutline(ProposedAble, Display, FinalizedDumpAble):
|
|
389
428
|
|
390
429
|
|
391
430
|
# <editor-fold desc="Article">
|
392
|
-
class Paragraph(
|
431
|
+
class Paragraph(CensoredAble):
|
393
432
|
"""Structured academic paragraph blueprint for controlled content generation."""
|
394
433
|
|
395
434
|
description: str
|
@@ -401,255 +440,273 @@ class Paragraph(ProposedAble):
|
|
401
440
|
Example: ['Introduce gradient-based NAS', 'Compare computational costs',
|
402
441
|
'Link efficiency to practical applications']"""
|
403
442
|
|
404
|
-
|
405
|
-
"""
|
406
|
-
1. Topic Sentence: Principal claim/position (1 sentence)
|
407
|
-
2. Development: Evidence chain with citations (2-4 sentences)
|
408
|
-
3. Synthesis: Interpretation & significance (1 sentence)
|
409
|
-
4. Transition: Logical bridge to next paragraph (optional)
|
410
|
-
|
411
|
-
Example: [
|
412
|
-
'Differentiable NAS revolutionized architecture search efficiency.',
|
413
|
-
'DARTS reduced search costs from 2000+ to 4 GPU days (Liu et al., 2019) while maintaining competitive ImageNet accuracy.',
|
414
|
-
'This order-of-magnitude improvement enables NAS deployment in resource-constrained research contexts.',
|
415
|
-
'These efficiency gains directly impact our framework's design choices as detailed in Section 3.'
|
416
|
-
]"""
|
417
|
-
|
418
|
-
|
419
|
-
class SectionRef(ProposedAble):
|
420
|
-
"""Cross-component reference system for maintaining document consistency."""
|
421
|
-
|
422
|
-
ref_chapter_title: str
|
423
|
-
"""Title of referenced chapter (e.g., 'Methodology')"""
|
424
|
-
|
425
|
-
ref_section_title: str
|
426
|
-
"""Exact section header text (e.g., '3.2 Gradient Optimization')"""
|
443
|
+
sentences: List[str]
|
444
|
+
"""List of sentences forming the paragraph's content."""
|
427
445
|
|
428
|
-
ref_subsection_title: str
|
429
|
-
"""Specific subsection identifier (e.g., '3.2.1 Learning Rate Scheduling')"""
|
430
446
|
|
431
|
-
|
432
|
-
class ArticleBase(ProposedAble, Display):
|
447
|
+
class ArticleBase(CensoredAble, Display, ArticleOutlineBase):
|
433
448
|
"""Foundation for hierarchical document components with dependency tracking."""
|
434
449
|
|
435
|
-
|
436
|
-
|
437
|
-
|
450
|
+
@abstractmethod
|
451
|
+
def to_typst_code(self) -> str:
|
452
|
+
"""Converts the component into a Typst code snippet for rendering."""
|
438
453
|
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
454
|
+
def _update_pre_check(self, other: Self) -> Self:
|
455
|
+
if not isinstance(other, self.__class__):
|
456
|
+
raise TypeError(f"Cannot update from a non-{self.__class__} instance.")
|
457
|
+
if self.title != other.title:
|
458
|
+
raise ValueError("Cannot update from a different title.")
|
443
459
|
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
460
|
+
@abstractmethod
|
461
|
+
def _update_from_inner(self, other: Self) -> Self:
|
462
|
+
"""Updates the current instance with the attributes of another instance."""
|
463
|
+
|
464
|
+
@final
|
465
|
+
def update_from(self, other: Self) -> Self:
|
466
|
+
"""Updates the current instance with the attributes of another instance."""
|
467
|
+
return self._update_pre_check(other)._update_from_inner(other)
|
449
468
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
Example: [SectionRef(chapter='Results', section='4.1', subsection='4.1.2')]"""
|
469
|
+
def __eq__(self, other: "ArticleBase") -> bool:
|
470
|
+
"""Compares two ArticleBase objects based on their model_dump_json representation."""
|
471
|
+
return self.model_dump_json() == other.model_dump_json()
|
454
472
|
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
Example: [SectionRef(chapter='Methods', section='2.3', subsection='2.3.4')]"""
|
473
|
+
def __hash__(self) -> int:
|
474
|
+
"""Calculates a hash value for the ArticleBase object based on its model_dump_json representation."""
|
475
|
+
return hash(self.model_dump_json())
|
459
476
|
|
460
477
|
|
461
478
|
class ArticleSubsection(ArticleBase):
|
462
479
|
"""Atomic argumentative unit with technical specificity."""
|
463
480
|
|
464
|
-
|
465
|
-
"""
|
466
|
-
Format: [Method]-[Domain]-[Innovation]
|
467
|
-
Example: 'Transformer-Based Architecture Search Space'"""
|
468
|
-
|
469
|
-
support_to: List[SectionRef]
|
470
|
-
"""Immediate parent components and supported hypotheses.
|
471
|
-
Example: [SectionRef(chapter='Methods', section='3', subsection='3.1')]"""
|
472
|
-
|
473
|
-
depend_on: List[SectionRef]
|
474
|
-
"""Technical dependencies including equations, algorithms, and datasets.
|
475
|
-
Example: [SectionRef(chapter='Background', section='2.2', subsection='2.2.3')]"""
|
476
|
-
|
477
|
-
paragraphs: List[Paragraph] = Field(..., min_length=3, max_length=5)
|
478
|
-
"""Technical exposition following ACM writing guidelines:
|
479
|
-
1. Contextualization: Position in research design
|
480
|
-
2. Technical Detail: Equations/algorithms/code
|
481
|
-
3. Validation: Citations/experimental confirmation
|
482
|
-
4. Interpretation: Scholarly significance
|
483
|
-
5. Transition: Logical connection to subsequent content
|
484
|
-
|
485
|
-
Example Paragraph Chain:
|
486
|
-
[
|
487
|
-
'Our search space builds on standard CNN architectures...',
|
488
|
-
'Formally, we define architecture parameters $\\alpha \\in R^d$ where...',
|
489
|
-
'This parameterization reduces search complexity by 42% compared to...',
|
490
|
-
'The efficiency gains validate our approach to...'
|
491
|
-
]"""
|
481
|
+
paragraphs: List[Paragraph]
|
482
|
+
"""List of Paragraph objects containing the content of the subsection."""
|
492
483
|
|
484
|
+
def _update_from_inner(self, other: Self) -> Self:
|
485
|
+
"""Updates the current instance with the attributes of another instance."""
|
486
|
+
logger.debug(f"Updating SubSection {self.title}")
|
487
|
+
self.paragraphs = other.paragraphs
|
488
|
+
return self
|
493
489
|
|
494
|
-
|
495
|
-
|
490
|
+
def to_typst_code(self) -> str:
|
491
|
+
"""Converts the component into a Typst code snippet for rendering.
|
496
492
|
|
497
|
-
|
498
|
-
|
499
|
-
|
493
|
+
Returns:
|
494
|
+
str: Typst code snippet for rendering.
|
495
|
+
"""
|
496
|
+
return f"=== {self.title}\n" + "\n\n".join("".join(p.sentences) for p in self.paragraphs)
|
500
497
|
|
501
|
-
support_to: List[SectionRef]
|
502
|
-
"""Supported research questions and paper-level claims.
|
503
|
-
Example: [SectionRef(chapter='Introduction', section='1', subsection='1.2')]"""
|
504
498
|
|
505
|
-
|
506
|
-
"""
|
507
|
-
Example: [SectionRef(chapter='Background', section='2', subsection='2.4')]"""
|
499
|
+
class ArticleSection(ArticleBase):
|
500
|
+
"""Atomic argumentative unit with high-level specificity."""
|
508
501
|
|
509
|
-
subsections: List[ArticleSubsection]
|
510
|
-
"""Thematic progression implementing section's research function:
|
511
|
-
1. Conceptual Framework
|
512
|
-
2. Technical Implementation
|
513
|
-
3. Experimental Validation
|
514
|
-
4. Comparative Analysis
|
515
|
-
5. Synthesis
|
502
|
+
subsections: List[ArticleSubsection]
|
516
503
|
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
'Ablation Studies',
|
523
|
-
'Interpretation Framework'
|
524
|
-
]"""
|
504
|
+
def _update_from_inner(self, other: Self) -> Self:
|
505
|
+
"""Updates the current instance with the attributes of another instance."""
|
506
|
+
for self_subsec, other_subsec in zip(self.subsections, other.subsections, strict=True):
|
507
|
+
self_subsec.update_from(other_subsec)
|
508
|
+
return self
|
525
509
|
|
510
|
+
def to_typst_code(self) -> str:
|
511
|
+
"""Converts the section into a Typst formatted code snippet.
|
526
512
|
|
527
|
-
|
528
|
-
|
513
|
+
Returns:
|
514
|
+
str: The formatted Typst code snippet.
|
515
|
+
"""
|
516
|
+
return f"== {self.title}\n" + "\n\n".join(subsec.to_typst_code() for subsec in self.subsections)
|
529
517
|
|
530
|
-
title: str = Field(...)
|
531
|
-
"""Standard IMRaD chapter title with domain specification.
|
532
|
-
Example: 'Neural Architecture Search for Low-Resource Languages'"""
|
533
518
|
|
534
|
-
|
535
|
-
"""
|
536
|
-
Example: [SectionRef(chapter='Abstract', section='', subsection='')]"""
|
519
|
+
class ArticleChapter(ArticleBase):
|
520
|
+
"""Thematic progression implementing research function."""
|
537
521
|
|
538
|
-
|
539
|
-
"""
|
540
|
-
Example: [SectionRef(chapter='Related Work', section='2', subsection='2.3')]"""
|
522
|
+
sections: List[ArticleSection]
|
523
|
+
"""Thematic progression implementing chapter's research function."""
|
541
524
|
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
4. Critical Analysis
|
548
|
-
5. Synthesis
|
525
|
+
def _update_from_inner(self, other: Self) -> Self:
|
526
|
+
"""Updates the current instance with the attributes of another instance."""
|
527
|
+
for self_sec, other_sec in zip(self.sections, other.sections, strict=True):
|
528
|
+
self_sec.update_from(other_sec)
|
529
|
+
return self
|
549
530
|
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
'Experimental Design',
|
554
|
-
'Results Analysis',
|
555
|
-
'Threats to Validity',
|
556
|
-
'Comparative Discussion'
|
557
|
-
]"""
|
531
|
+
def to_typst_code(self) -> str:
|
532
|
+
"""Converts the chapter into a Typst formatted code snippet for rendering."""
|
533
|
+
return f"= {self.title}\n" + "\n\n".join(sec.to_typst_code() for sec in self.sections)
|
558
534
|
|
559
535
|
|
560
|
-
class Article(
|
536
|
+
class Article(Display, CensoredAble, WithRef[ArticleOutline]):
|
561
537
|
"""Complete academic paper specification with validation constraints."""
|
562
538
|
|
563
539
|
title: str = Field(...)
|
564
|
-
"""
|
565
|
-
Structure: [Method] for [Task] in [Domain]: [Subtitle with Technical Focus]
|
566
|
-
Example: 'Efficient Differentiable NAS for Low-Resource MT:
|
567
|
-
A Parameter-Sharing Approach to Cross-Lingual Transfer'"""
|
540
|
+
"""The academic title"""
|
568
541
|
|
569
542
|
abstract: str = Field(...)
|
570
|
-
"""
|
571
|
-
1. Context: 2 clauses (problem + gap)
|
572
|
-
2. Methods: 3 clauses (approach + innovation + implementation)
|
573
|
-
3. Results: 3 clauses (metrics + comparisons + significance)
|
574
|
-
4. Impact: 2 clauses (theoretical + practical)
|
575
|
-
|
576
|
-
Example: 'Neural architecture search (NAS) faces prohibitive... [150 words]'"""
|
577
|
-
|
578
|
-
chapters: List[ArticleChapter] = Field(..., min_length=5, max_length=8)
|
579
|
-
"""IMRaD-compliant document structure with enhanced validation:
|
580
|
-
1. Introduction: Motivation & Contributions
|
581
|
-
2. Background: Literature & Theory
|
582
|
-
3. Methods: Technical Implementation
|
583
|
-
4. Experiments: Protocols & Setup
|
584
|
-
5. Results: Empirical Findings
|
585
|
-
6. Discussion: Interpretation & Limitations
|
586
|
-
7. Conclusion: Summary & Future Work
|
543
|
+
"""Abstract of the academic paper."""
|
587
544
|
|
588
|
-
|
545
|
+
chapters: List[ArticleChapter]
|
546
|
+
"""List of ArticleChapter objects representing the academic paper's structure."""
|
589
547
|
|
590
|
-
def
|
591
|
-
"""
|
548
|
+
def finalized_dump(self) -> str:
|
549
|
+
"""Exports the article in `typst` format.
|
550
|
+
|
551
|
+
Returns:
|
552
|
+
str: Strictly formatted outline with typst formatting.
|
553
|
+
"""
|
554
|
+
return "\n\n".join(c.to_typst_code() for c in self.chapters)
|
555
|
+
|
556
|
+
@classmethod
|
557
|
+
def from_outline(cls, outline: ArticleOutline) -> "Article":
|
558
|
+
"""Generates an article from the given outline.
|
592
559
|
|
593
560
|
Args:
|
594
|
-
outline (ArticleOutline): The outline to
|
561
|
+
outline (ArticleOutline): The outline to generate the article from.
|
595
562
|
|
596
563
|
Returns:
|
597
|
-
|
564
|
+
Article: The generated article.
|
598
565
|
"""
|
599
566
|
# Set the title from the outline
|
600
|
-
|
567
|
+
article = Article(**outline.model_dump(include={"title", "abstract"}), chapters=[])
|
601
568
|
|
602
|
-
|
603
|
-
self.chapters = []
|
604
|
-
|
605
|
-
for chapter_outline in outline.chapters:
|
569
|
+
for chapter in outline.chapters:
|
606
570
|
# Create a new chapter
|
607
|
-
|
608
|
-
title=chapter_outline.title,
|
609
|
-
description=chapter_outline.description,
|
610
|
-
writing_aim=["Implement " + chapter_outline.description],
|
611
|
-
support_to=[],
|
612
|
-
depend_on=[],
|
571
|
+
article_chapter = ArticleChapter(
|
613
572
|
sections=[],
|
573
|
+
**chapter.model_dump(exclude={"sections"}),
|
614
574
|
)
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
section = ArticleSection(
|
619
|
-
title=section_outline.title,
|
620
|
-
description=section_outline.description,
|
621
|
-
writing_aim=["Address " + section_outline.description],
|
622
|
-
support_to=[],
|
623
|
-
depend_on=[],
|
575
|
+
for section in chapter.sections:
|
576
|
+
# Create a new section
|
577
|
+
article_section = ArticleSection(
|
624
578
|
subsections=[],
|
579
|
+
**section.model_dump(exclude={"subsections"}),
|
625
580
|
)
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
description=subsection_outline.description,
|
632
|
-
writing_aim=["Explain " + subsection_outline.description],
|
633
|
-
support_to=[],
|
634
|
-
depend_on=[],
|
635
|
-
paragraphs=[
|
636
|
-
Paragraph(
|
637
|
-
description=f"Implementation of {subsection_outline.title}",
|
638
|
-
writing_aim=["Present key concepts", "Support main arguments"],
|
639
|
-
lines=[],
|
640
|
-
)
|
641
|
-
],
|
581
|
+
for subsection in section.subsections:
|
582
|
+
# Create a new subsection
|
583
|
+
article_subsection = ArticleSubsection(
|
584
|
+
paragraphs=[],
|
585
|
+
**subsection.model_dump(),
|
642
586
|
)
|
643
|
-
|
587
|
+
article_section.subsections.append(article_subsection)
|
588
|
+
article_chapter.sections.append(article_section)
|
589
|
+
article.chapters.append(article_chapter)
|
590
|
+
return article
|
644
591
|
|
645
|
-
|
592
|
+
def chap_iter(self) -> Generator[ArticleChapter, None, None]:
|
593
|
+
"""Iterates over all chapters in the article.
|
646
594
|
|
647
|
-
|
595
|
+
Yields:
|
596
|
+
ArticleChapter: Each chapter in the article.
|
597
|
+
"""
|
598
|
+
yield from self.chapters
|
648
599
|
|
649
|
-
|
650
|
-
|
600
|
+
def section_iter(self) -> Generator[ArticleSection, None, None]:
|
601
|
+
"""Iterates over all sections in the article.
|
651
602
|
|
652
|
-
|
603
|
+
Yields:
|
604
|
+
ArticleSection: Each section in the article.
|
605
|
+
"""
|
606
|
+
for chap in self.chapters:
|
607
|
+
yield from chap.sections
|
608
|
+
|
609
|
+
def subsection_iter(self) -> Generator[ArticleSubsection, None, None]:
|
610
|
+
"""Iterates over all subsections in the article.
|
611
|
+
|
612
|
+
Yields:
|
613
|
+
ArticleSubsection: Each subsection in the article.
|
614
|
+
"""
|
615
|
+
for sec in self.section_iter():
|
616
|
+
yield from sec.subsections
|
617
|
+
|
618
|
+
def iter_dfs(self) -> Generator[ArticleBase, None, None]:
|
619
|
+
"""Performs a depth-first search (DFS) through the article structure.
|
620
|
+
|
621
|
+
Returns:
|
622
|
+
Generator[ArticleBase]: Each component in the article structure.
|
623
|
+
"""
|
624
|
+
for chap in self.chap_iter():
|
625
|
+
for sec in chap.sections:
|
626
|
+
yield from sec.subsections
|
627
|
+
yield sec
|
628
|
+
yield chap
|
629
|
+
|
630
|
+
def deref(self, ref: ArticleRef) -> ArticleBase:
|
631
|
+
"""Resolves a reference to the corresponding section or subsection in the article.
|
632
|
+
|
633
|
+
Args:
|
634
|
+
ref (ArticleRef): The reference to resolve.
|
635
|
+
|
636
|
+
Returns:
|
637
|
+
ArticleBase: The corresponding section or subsection.
|
638
|
+
"""
|
639
|
+
chap = ok(
|
640
|
+
next(chap for chap in self.chap_iter() if chap.title == ref.referred_chapter_title), "Chapter not found"
|
641
|
+
)
|
642
|
+
if ref.referred_section_title is None:
|
643
|
+
return chap
|
644
|
+
sec = ok(next(sec for sec in chap.sections if sec.title == ref.referred_section_title))
|
645
|
+
if ref.referred_subsection_title is None:
|
646
|
+
return sec
|
647
|
+
return ok(next(subsec for subsec in sec.subsections if subsec.title == ref.referred_subsection_title))
|
648
|
+
|
649
|
+
def gather_dependencies(self, article: ArticleBase) -> List[ArticleBase]:
|
650
|
+
"""Gathers dependencies for all sections and subsections in the article.
|
651
|
+
|
652
|
+
This method should be called after the article is fully constructed.
|
653
|
+
"""
|
654
|
+
depends = [self.deref(a) for a in article.depend_on]
|
655
|
+
|
656
|
+
supports = []
|
657
|
+
for a in self.iter_dfs():
|
658
|
+
if article in {self.deref(b) for b in a.support_to}:
|
659
|
+
supports.append(a)
|
660
|
+
|
661
|
+
return list(set(depends + supports))
|
662
|
+
|
663
|
+
def gather_dependencies_recursive(self, article: ArticleBase) -> List[ArticleBase]:
|
664
|
+
"""Gathers all dependencies recursively for the given article.
|
665
|
+
|
666
|
+
Args:
|
667
|
+
article (ArticleBase): The article to gather dependencies for.
|
668
|
+
|
669
|
+
Returns:
|
670
|
+
List[ArticleBase]: A list of all dependencies for the given article.
|
671
|
+
"""
|
672
|
+
q = self.gather_dependencies(article)
|
673
|
+
|
674
|
+
deps = []
|
675
|
+
while a := q.pop():
|
676
|
+
deps.extend(self.gather_dependencies(a))
|
677
|
+
|
678
|
+
deps = list(
|
679
|
+
chain(
|
680
|
+
filter(lambda x: isinstance(x, ArticleChapter), deps),
|
681
|
+
filter(lambda x: isinstance(x, ArticleSection), deps),
|
682
|
+
filter(lambda x: isinstance(x, ArticleSubsection), deps),
|
683
|
+
)
|
684
|
+
)
|
685
|
+
|
686
|
+
# Initialize result containers
|
687
|
+
formatted_code = ""
|
688
|
+
processed_components = []
|
689
|
+
|
690
|
+
# Process all dependencies
|
691
|
+
while component := deps.pop():
|
692
|
+
# Skip duplicates
|
693
|
+
if (component_code := component.to_typst_code()) in formatted_code:
|
694
|
+
continue
|
695
|
+
|
696
|
+
# Add this component
|
697
|
+
formatted_code += component_code
|
698
|
+
processed_components.append(component)
|
699
|
+
|
700
|
+
return processed_components
|
701
|
+
|
702
|
+
def iter_dfs_with_deps(self) -> Generator[Tuple[ArticleBase, List[ArticleBase]], None, None]:
|
703
|
+
"""Iterates through the article in a depth-first manner, yielding each component and its dependencies.
|
704
|
+
|
705
|
+
Yields:
|
706
|
+
Tuple[ArticleBase, List[ArticleBase]]: Each component and its dependencies.
|
707
|
+
"""
|
708
|
+
for component in self.iter_dfs():
|
709
|
+
yield component, (self.gather_dependencies_recursive(component))
|
653
710
|
|
654
711
|
|
655
712
|
# </editor-fold>
|