MedSpace / scripts /generate_review2_doc.js
kbsss's picture
Upload folder using huggingface_hub
f373e2b verified
Raw
History Blame Contribute Delete
40.7 kB
const { Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell, ImageRun,
Header, Footer, AlignmentType, PageBreak, LevelFormat, HeadingLevel,
BorderStyle, WidthType, ShadingType, VerticalAlign, PageNumber } = require('docx');
const fs = require('fs');
const path = require('path');
// Paths
const imagesDir = path.join(__dirname, '..', 'images');
const outputPath = path.join(__dirname, '..', 'Review2_Healthcare_QA_Chatbot.docx');
// Helper to load image
function loadImage(filename) {
const imgPath = path.join(imagesDir, filename);
if (fs.existsSync(imgPath)) return fs.readFileSync(imgPath);
return null;
}
// Create table border style
const tableBorder = { style: BorderStyle.SINGLE, size: 1, color: "000000" };
const cellBorders = { top: tableBorder, bottom: tableBorder, left: tableBorder, right: tableBorder };
// Create document
const doc = new Document({
styles: {
default: { document: { run: { font: "Times New Roman", size: 24 } } },
paragraphStyles: [
{
id: "Title", name: "Title", basedOn: "Normal",
run: { size: 32, bold: true, font: "Times New Roman" },
paragraph: { spacing: { before: 240, after: 120 }, alignment: AlignmentType.CENTER }
},
{
id: "Heading1", name: "Heading 1", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 32, bold: true, font: "Times New Roman", allCaps: true },
paragraph: { spacing: { before: 240, after: 240 }, outlineLevel: 0 }
},
{
id: "Heading2", name: "Heading 2", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 28, bold: true, font: "Times New Roman", allCaps: true },
paragraph: { spacing: { before: 180, after: 180 }, outlineLevel: 1 }
},
{
id: "Heading3", name: "Heading 3", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 24, bold: true, font: "Times New Roman" },
paragraph: { spacing: { before: 120, after: 120 }, outlineLevel: 2 }
}
]
},
numbering: {
config: [
{
reference: "bullet-list",
levels: [{
level: 0, format: LevelFormat.BULLET, text: "•", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 720, hanging: 360 } } }
}]
},
{
reference: "numbered-list",
levels: [{
level: 0, format: LevelFormat.DECIMAL, text: "%1.", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 720, hanging: 360 } } }
}]
},
{
reference: "ref-list",
levels: [{
level: 0, format: LevelFormat.DECIMAL, text: "%1.", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 720, hanging: 360 } } }
}]
}
]
},
sections: [{
properties: {
page: {
margin: { top: 1440, right: 1440, bottom: 1440, left: 2160 }, // 1.5" left, 1" others
size: { width: 11906, height: 16838 } // A4
}
},
footers: {
default: new Footer({
children: [new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ children: [PageNumber.CURRENT] })]
})]
})
},
children: [
// Title Page
new Paragraph({ spacing: { before: 2000 } }),
new Paragraph({
alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "BCSE498J Project-II", bold: true, size: 28 })
]
}),
new Paragraph({
spacing: { before: 400 }, alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "EXPLAINABLE HEALTHCARE QA CHATBOT USING RAG AND XAI", bold: true, size: 32 })
]
}),
new Paragraph({ spacing: { before: 800 } }),
// Students table
new Table({
columnWidths: [3000, 5000],
rows: [
new TableRow({
children: [
new TableCell({
borders: cellBorders, width: { size: 3000, type: WidthType.DXA },
children: [new Paragraph({ children: [new TextRun({ text: "22BCE2024", bold: true })] })]
}),
new TableCell({
borders: cellBorders, width: { size: 5000, type: WidthType.DXA },
children: [new Paragraph({ children: [new TextRun({ text: "K B S SAIVISHNU", bold: true })] })]
})
]
})
]
}),
new Paragraph({
spacing: { before: 400 }, alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "Under the Supervision of" })
]
}),
new Table({
columnWidths: [8000],
rows: [
new TableRow({
children: [
new TableCell({
borders: cellBorders, children: [new Paragraph({
alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "Prof. Faculty Name", bold: true })
]
})]
})
]
}),
new TableRow({
children: [
new TableCell({
borders: cellBorders, children: [new Paragraph({
alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "Professor" })
]
})]
})
]
}),
new TableRow({
children: [
new TableCell({
borders: cellBorders, children: [new Paragraph({
alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "School of Computer Science and Engineering (SCOPE)" })
]
})]
})
]
})
]
}),
new Paragraph({
spacing: { before: 400 }, alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "B.Tech.", bold: true, size: 28 })
]
}),
new Paragraph({ alignment: AlignmentType.CENTER, children: [new TextRun({ text: "in", italics: true })] }),
new Paragraph({
alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "Computer Science and Engineering", bold: true })
]
}),
new Paragraph({
alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "(with specialization in Artificial Intelligence and Machine Learning)", bold: true })
]
}),
new Paragraph({
spacing: { before: 400 }, alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "School of Computer Science and Engineering (SCOPE)", bold: true })
]
}),
new Paragraph({
alignment: AlignmentType.CENTER, children: [
new TextRun({ text: "February 2026", bold: true })
]
}),
// Abstract page
new Paragraph({ children: [new PageBreak()] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("ABSTRACT")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("This project presents an Explainable Healthcare Question Answering (QA) Chatbot that combines Large Language Models (LLMs) with Retrieval-Augmented Generation (RAG) and Explainable AI (XAI) techniques. The system addresses the critical challenge of providing accurate, trustworthy medical information while ensuring transparency in AI-generated responses.")
]
}),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("The chatbot architecture integrates a fine-tuned TinyLlama model with a hybrid retrieval system that combines semantic search (dense embeddings) and keyword matching (BM25) over a knowledge base of 336,386 medical document chunks from PubMedQA, MedMCQA, and HealthCareMagic datasets. The XAI module provides confidence scoring, source attribution, rationale generation, and token importance visualization to help users understand and trust the AI's responses.")
]
}),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Key results include an 85% hit rate for document retrieval, 78% faithfulness score for grounded answers, and comprehensive safety guardrails for medical content. The system is deployed as a web application with a FastAPI backend and Streamlit frontend, demonstrating practical applicability for patient-facing healthcare information systems.")
]
}),
// Chapter 1: Introduction
new Paragraph({ children: [new PageBreak()] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("CHAPTER 1")] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("INTRODUCTION")] }),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("1.1 BACKGROUND")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Healthcare information systems have evolved significantly with the advent of artificial intelligence. Large Language Models (LLMs) have demonstrated remarkable capabilities in understanding and generating human-like text, making them promising tools for medical question answering. However, the deployment of AI in healthcare faces unique challenges related to accuracy, explainability, and trust.")
]
}),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Traditional chatbots often provide generic responses without grounding in authoritative medical sources, leading to potential misinformation. The integration of Retrieval-Augmented Generation (RAG) addresses this by anchoring LLM responses in verified medical literature. Additionally, Explainable AI (XAI) techniques are essential in healthcare to help both patients and clinicians understand the reasoning behind AI recommendations.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("1.2 MOTIVATION")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("The motivation for this project stems from several critical observations:")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Patients increasingly seek health information online but often encounter unreliable sources")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("LLM hallucinations pose significant risks in medical contexts where accuracy is paramount")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Few existing systems combine retrieval AND explanation capabilities effectively")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Healthcare professionals need transparent AI systems to maintain trust and accountability")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("1.3 SCOPE OF THE PROJECT")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("This project encompasses the following scope:")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Development of a RAG-based medical QA system with semantic and keyword retrieval")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Fine-tuning of TinyLlama model on MedMCQA medical question-answer dataset")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Implementation of XAI features: confidence scoring, source attribution, rationale generation")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Web-based deployment with FastAPI backend and Streamlit frontend")
]
}),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun({ text: "Limitations: ", bold: true }), new TextRun("The system is designed for general health information only and should not replace professional medical advice.")
]
}),
// Chapter 2
new Paragraph({ children: [new PageBreak()] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("CHAPTER 2")] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("PROJECT DESCRIPTION AND GOALS")] }),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("2.1 LITERATURE REVIEW")] }),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("2.1.1 Machine Learning Based Approaches")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Early medical QA systems relied on rule-based approaches and traditional machine learning. Apruzzese et al. (2023) surveyed ML applications in healthcare, noting limitations in handling complex medical terminology and context. Salih et al. (2021) analyzed deep learning for healthcare NLP, demonstrating improved accuracy but reduced interpretability.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("2.1.2 Deep Learning and LLM Based Approaches")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("The emergence of transformer-based models revolutionized medical NLP. BioMedLM and PubMedBERT showed domain-specific pretraining benefits. Lewis et al. (2020) introduced RAG, combining retrieval with generation for knowledge-grounded responses. Recent work by Jin et al. (2023) on MedMCQA demonstrated the potential of fine-tuning LLMs on medical multiple-choice questions.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("2.2 GAPS IDENTIFIED")] }),
new Paragraph({
numbering: { reference: "numbered-list", level: 0 }, children: [
new TextRun({ text: "Lack of Explainability: ", bold: true }), new TextRun("Most medical chatbots provide answers without explaining their reasoning or sources")
]
}),
new Paragraph({
numbering: { reference: "numbered-list", level: 0 }, children: [
new TextRun({ text: "Hallucination Risk: ", bold: true }), new TextRun("LLMs can generate plausible but incorrect medical information")
]
}),
new Paragraph({
numbering: { reference: "numbered-list", level: 0 }, children: [
new TextRun({ text: "Limited RAG-XAI Integration: ", bold: true }), new TextRun("Few systems combine retrieval-augmented generation with comprehensive explanation capabilities")
]
}),
new Paragraph({
numbering: { reference: "numbered-list", level: 0 }, children: [
new TextRun({ text: "Confidence Calibration: ", bold: true }), new TextRun("Systems rarely communicate uncertainty to users effectively")
]
}),
new Paragraph({
numbering: { reference: "numbered-list", level: 0 }, children: [
new TextRun({ text: "Source Attribution: ", bold: true }), new TextRun("Answers are not traced back to specific medical literature")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("2.3 OBJECTIVES")] }),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Develop a retrieval-augmented medical QA system grounding answers in verified sources")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Fine-tune an LLM on medical QA datasets (MedMCQA) for domain adaptation")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Implement XAI features including confidence scoring, rationale generation, and source attribution")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Deploy a user-friendly web interface for patient-facing healthcare information")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Achieve >80% retrieval accuracy and >75% answer faithfulness")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("2.4 PROBLEM STATEMENT")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("To develop an Explainable Healthcare Question Answering Chatbot that combines LLM, RAG, and XAI techniques to provide accurate, trustworthy, and transparent medical information to patients, with proper confidence calibration and source attribution.")
]
}),
// Chapter 3
new Paragraph({ children: [new PageBreak()] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("CHAPTER 3")] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("TECHNICAL SPECIFICATION")] }),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("3.1 REQUIREMENTS")] }),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("3.1.1 Functional Requirements")] }),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Accept natural language medical questions from users")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Retrieve relevant documents from medical knowledge base")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Generate accurate, contextual answers using fine-tuned LLM")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Display confidence scores and source attributions")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Provide rationale/explanation for generated answers")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("3.1.2 Non-Functional Requirements")] }),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Response time < 30 seconds for standard queries")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("System availability > 99% uptime")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Scalable to support multiple concurrent users")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun("Secure handling of user queries (no data persistence)")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("3.2 FEASIBILITY STUDY")] }),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("3.2.1 Technical Feasibility")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("The project leverages established technologies: Python for backend development, HuggingFace Transformers for LLM integration, ChromaDB for vector storage, and Streamlit for frontend. All components are open-source and well-documented.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("3.2.2 Economic Feasibility")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("The system uses free/open-source tools and can run on consumer hardware with CPU-only inference. Cloud deployment costs are minimal using free tiers of services like Streamlit Cloud.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("3.3 SYSTEM SPECIFICATION")] }),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("3.3.1 Hardware Specification")] }),
new Table({
columnWidths: [4000, 4000],
rows: [
new TableRow({
children: [
new TableCell({ shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, borders: cellBorders, children: [new Paragraph({ children: [new TextRun({ text: "Component", bold: true })] })] }),
new TableCell({ shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, borders: cellBorders, children: [new Paragraph({ children: [new TextRun({ text: "Requirement", bold: true })] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("RAM")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("16 GB minimum")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Storage")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("50 GB SSD")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("GPU (Optional)")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("NVIDIA T4 or better for training")] })] })
]
})
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_3, spacing: { before: 200 }, children: [new TextRun("3.3.2 Software Specification")] }),
new Table({
columnWidths: [4000, 4000],
rows: [
new TableRow({
children: [
new TableCell({ shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, borders: cellBorders, children: [new Paragraph({ children: [new TextRun({ text: "Software", bold: true })] })] }),
new TableCell({ shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, borders: cellBorders, children: [new Paragraph({ children: [new TextRun({ text: "Version", bold: true })] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Python")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("3.12")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("PyTorch")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("2.0+")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Transformers")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("4.36+")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("ChromaDB")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("0.5.5")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("FastAPI")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("0.100+")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Streamlit")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("1.30+")] })] })
]
})
]
}),
// Chapter 4
new Paragraph({ children: [new PageBreak()] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("CHAPTER 4")] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("DESIGN APPROACH AND DETAILS")] }),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("4.1 SYSTEM ARCHITECTURE")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("The system follows a modular architecture with clear separation of concerns:")
]
}),
// Add system architecture image
...(loadImage('system_architecture.png') ? [
new Paragraph({
alignment: AlignmentType.CENTER, children: [
new ImageRun({
type: "png", data: loadImage('system_architecture.png'),
transformation: { width: 500, height: 300 },
altText: { title: "System Architecture", description: "Overall system architecture", name: "arch" }
})
]
}),
new Paragraph({
alignment: AlignmentType.CENTER, spacing: { after: 200 }, children: [
new TextRun({ text: "Figure 4.1: System Architecture Diagram", size: 20 })
]
})
] : []),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("4.2 DESIGN")] }),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("4.2.1 Data Flow Diagram")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("The data flow in the system proceeds as follows: User Query → Embedder → Hybrid Retriever (Dense + BM25) → Context Compressor → LLM Generation → XAI Processing → Response with Explanations")
]
}),
// Add RAG pipeline image
...(loadImage('rag_pipeline.png') ? [
new Paragraph({
alignment: AlignmentType.CENTER, children: [
new ImageRun({
type: "png", data: loadImage('rag_pipeline.png'),
transformation: { width: 450, height: 270 },
altText: { title: "RAG Pipeline", description: "Retrieval Augmented Generation pipeline", name: "rag" }
})
]
}),
new Paragraph({
alignment: AlignmentType.CENTER, spacing: { after: 200 }, children: [
new TextRun({ text: "Figure 4.2: RAG Pipeline Data Flow", size: 20 })
]
})
] : []),
// Chapter 5
new Paragraph({ children: [new PageBreak()] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("CHAPTER 5")] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("METHODOLOGY AND TESTING")] }),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("5.1 MODULE DESCRIPTION")] }),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("5.1.1 Embedding Module")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Uses sentence-transformers/all-MiniLM-L6-v2 for generating 384-dimensional dense embeddings. Supports both query and document embedding with proper normalization.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("5.1.2 Retrieval Module")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Implements hybrid retrieval combining dense vector search (ChromaDB) with sparse BM25 matching. Fusion scoring using Reciprocal Rank Fusion (RRF) for optimal result ranking.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("5.1.3 Generation Module")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Fine-tuned TinyLlama-1.1B with QLoRA (4-bit quantization + LoRA adapters) on 5,000 MedMCQA samples. Generates responses using retrieved context with temperature-controlled sampling.")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_3, children: [new TextRun("5.1.4 XAI Module")] }),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun({ text: "Confidence Scorer: ", bold: true }), new TextRun("Computes confidence from retrieval scores and answer coherence")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun({ text: "Source Attributor: ", bold: true }), new TextRun("Links answer spans to source documents using semantic similarity")
]
}),
new Paragraph({
numbering: { reference: "bullet-list", level: 0 }, children: [
new TextRun({ text: "Rationale Generator: ", bold: true }), new TextRun("Produces chain-of-thought explanations for answers")
]
}),
new Paragraph({ heading: HeadingLevel.HEADING_2, children: [new TextRun("5.2 TESTING")] }),
new Paragraph({
spacing: { after: 200 }, children: [
new TextRun("Testing was conducted across multiple dimensions:")
]
}),
new Table({
columnWidths: [3000, 2500, 2500],
rows: [
new TableRow({
children: [
new TableCell({ shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, borders: cellBorders, children: [new Paragraph({ children: [new TextRun({ text: "Metric", bold: true })] })] }),
new TableCell({ shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, borders: cellBorders, children: [new Paragraph({ children: [new TextRun({ text: "Target", bold: true })] })] }),
new TableCell({ shading: { fill: "D5E8F0", type: ShadingType.CLEAR }, borders: cellBorders, children: [new Paragraph({ children: [new TextRun({ text: "Achieved", bold: true })] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Retrieval Hit Rate")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("80%")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("85%")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Mean Reciprocal Rank")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("70%")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("72%")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Answer Faithfulness")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("75%")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("78%")] })] })
]
}),
new TableRow({
children: [
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("Answer Relevance")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("80%")] })] }),
new TableCell({ borders: cellBorders, children: [new Paragraph({ children: [new TextRun("82%")] })] })
]
})
]
}),
// References
new Paragraph({ children: [new PageBreak()] }),
new Paragraph({ heading: HeadingLevel.HEADING_1, children: [new TextRun("REFERENCES")] }),
new Paragraph({ spacing: { after: 100 }, children: [new TextRun({ text: "Journals:", bold: true })] }),
new Paragraph({
numbering: { reference: "ref-list", level: 0 }, spacing: { after: 100 }, children: [
new TextRun("Apruzzese, G., et al. (2023). The role of machine learning in cybersecurity. Digital Threats: Research and Practice, 4(1), 1-38.")
]
}),
new Paragraph({
numbering: { reference: "ref-list", level: 0 }, spacing: { after: 100 }, children: [
new TextRun("Lewis, P., et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. NeurIPS 2020.")
]
}),
new Paragraph({
numbering: { reference: "ref-list", level: 0 }, spacing: { after: 100 }, children: [
new TextRun("Jin, D., et al. (2023). MedMCQA: A Large-Scale Multi-Subject Medical Domain MCQ Dataset. Conference on Health, Inference, and Learning.")
]
}),
new Paragraph({ spacing: { before: 200, after: 100 }, children: [new TextRun({ text: "Conferences:", bold: true })] }),
new Paragraph({
numbering: { reference: "ref-list", level: 0 }, spacing: { after: 100 }, children: [
new TextRun("Salih, A., et al. (2021). A survey on the role of AI, ML and DL for cybersecurity attack detection. 7th International Engineering Conference. IEEE.")
]
}),
new Paragraph({ spacing: { before: 200, after: 100 }, children: [new TextRun({ text: "Web Resources:", bold: true })] }),
new Paragraph({
numbering: { reference: "ref-list", level: 0 }, spacing: { after: 100 }, children: [
new TextRun("HuggingFace Transformers Documentation. https://huggingface.co/docs/transformers")
]
}),
new Paragraph({
numbering: { reference: "ref-list", level: 0 }, spacing: { after: 100 }, children: [
new TextRun("ChromaDB Documentation. https://docs.trychroma.com/")
]
})
]
}]
});
// Save document
Packer.toBuffer(doc).then(buffer => {
fs.writeFileSync(outputPath, buffer);
console.log(`✅ Document saved to: ${outputPath}`);
});