TextSummarizer

Struct TextSummarizer 

Source
pub struct TextSummarizer { /* private fields */ }
Expand description

Text summarizer using quantum language models

Implementations§

Source§

impl TextSummarizer

Source

pub fn new(num_qubits: usize) -> Result<Self>

Creates a new text summarizer

Examples found in repository?
examples/quantum_nlp.rs (line 143)
133fn run_text_summarization() -> Result<()> {
134    println!("\nText Summarization Example");
135    println!("-------------------------");
136
137    // Create text summarizer
138    let num_qubits = 8;
139    println!(
140        "Creating quantum text summarizer with {} qubits",
141        num_qubits
142    );
143    let summarizer = quantrs2_ml::nlp::TextSummarizer::new(num_qubits)?;
144
145    // Text to summarize
146    let long_text = "Quantum computing is a rapidly-emerging technology that harnesses the laws of quantum mechanics to solve problems too complex for classical computers. While traditional computers use bits as the smallest unit of data, quantum computers use quantum bits or qubits. Qubits can represent numerous possible combinations of 1 and 0 at the same time through a property called superposition. This allows quantum computers to consider and manipulate many combinations of information simultaneously, making them well suited to specific types of complex calculations. Another key property of quantum computing is entanglement, which allows qubits that are separated by great distances to still be connected. Changing the state of one entangled qubit will instantaneously change the state of its partner regardless of how far apart they are. Quantum computers excel at solving certain types of problems, such as factoring very large numbers, searching unsorted databases, and simulating quantum systems like molecules for drug development. However, they are not expected to replace classical computers for most everyday tasks. Major technology companies including IBM, Google, Microsoft, Amazon, and several startups are racing to build practical quantum computers. In 2019, Google claimed to have achieved quantum supremacy, performing a calculation that would be practically impossible for a classical computer. While current quantum computers are still limited by high error rates and the need for extreme cooling, they represent one of the most promising frontier technologies of the 21st century.";
147
148    println!("\nOriginal text ({} characters):", long_text.len());
149    println!("{}\n", long_text);
150
151    // Generate summary
152    println!("Generating quantum summary...");
153    let start = Instant::now();
154    let summary = summarizer.summarize(long_text)?;
155    println!("Summarization completed in {:.2?}", start.elapsed());
156
157    println!("\nSummary ({} characters):", summary.len());
158    println!("{}", summary);
159
160    // Calculate compression ratio
161    let compression = 100.0 * (1.0 - (summary.len() as f64) / (long_text.len() as f64));
162    println!("\nCompression ratio: {:.1}%", compression);
163
164    Ok(())
165}
Source

pub fn with_max_length(self, max_length: usize) -> Self

Sets the maximum summary length

Source

pub fn summarize(&self, text: &str) -> Result<String>

Summarizes text

Examples found in repository?
examples/quantum_nlp.rs (line 154)
133fn run_text_summarization() -> Result<()> {
134    println!("\nText Summarization Example");
135    println!("-------------------------");
136
137    // Create text summarizer
138    let num_qubits = 8;
139    println!(
140        "Creating quantum text summarizer with {} qubits",
141        num_qubits
142    );
143    let summarizer = quantrs2_ml::nlp::TextSummarizer::new(num_qubits)?;
144
145    // Text to summarize
146    let long_text = "Quantum computing is a rapidly-emerging technology that harnesses the laws of quantum mechanics to solve problems too complex for classical computers. While traditional computers use bits as the smallest unit of data, quantum computers use quantum bits or qubits. Qubits can represent numerous possible combinations of 1 and 0 at the same time through a property called superposition. This allows quantum computers to consider and manipulate many combinations of information simultaneously, making them well suited to specific types of complex calculations. Another key property of quantum computing is entanglement, which allows qubits that are separated by great distances to still be connected. Changing the state of one entangled qubit will instantaneously change the state of its partner regardless of how far apart they are. Quantum computers excel at solving certain types of problems, such as factoring very large numbers, searching unsorted databases, and simulating quantum systems like molecules for drug development. However, they are not expected to replace classical computers for most everyday tasks. Major technology companies including IBM, Google, Microsoft, Amazon, and several startups are racing to build practical quantum computers. In 2019, Google claimed to have achieved quantum supremacy, performing a calculation that would be practically impossible for a classical computer. While current quantum computers are still limited by high error rates and the need for extreme cooling, they represent one of the most promising frontier technologies of the 21st century.";
147
148    println!("\nOriginal text ({} characters):", long_text.len());
149    println!("{}\n", long_text);
150
151    // Generate summary
152    println!("Generating quantum summary...");
153    let start = Instant::now();
154    let summary = summarizer.summarize(long_text)?;
155    println!("Summarization completed in {:.2?}", start.elapsed());
156
157    println!("\nSummary ({} characters):", summary.len());
158    println!("{}", summary);
159
160    // Calculate compression ratio
161    let compression = 100.0 * (1.0 - (summary.len() as f64) / (long_text.len() as f64));
162    println!("\nCompression ratio: {:.1}%", compression);
163
164    Ok(())
165}

Trait Implementations§

Source§

impl Clone for TextSummarizer

Source§

fn clone(&self) -> TextSummarizer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TextSummarizer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Ungil for T
where T: Send,